1 Simulación Proceso Espacio Temporal

1.1 Funciones

##Funciones de covarianza espacio temporal
exp_esp_temp=function(h,u,p){((p[1])^2)*exp(-h/p[2]-u/p[3])}
gauss_esp_temp=function(h,u,p){(p[1]^2)*exp(-(h/p[2])^2-(u/p[3])^2)}
cressie1=function(h,u,p){(p[1]^2/((p[2]^2*u^2+1)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
Gneiting1=function(h,u,p){p[1]^2/((p[2]*u^(2*p[3])+1)^(p[4]))*exp(-(p[6]*h^(2*p[5]))/((p[2]*u^(2*p[3])+1)^(p[4]*p[5])))}
#Gneiting2=function(h,u,sigma,p){p[1]^2/((2^(p[3]-1))*p[7](p[3])*(p[2]*u^(2*p[3])+1)^(p[4]+p[5]))*(((p[6]*h)/((p[2]*u^(2*[3])+1)^(p[5]/2)))^p[3])*besselK(((p[6]*h)/((p[2]*u^(2*[3])+1)^(p[5]/2))),p[3])}
Iaco_Cesare=function(h,u,a,b,c){(1+h^p[1]+u^p[2])^(-p[3])}
#separables mas comunes: gaussiano y exponencial   p=(sigma,a,b)
Gaussiano=function(p,h,u){p[1]^2*exp(-p[2]^2*u^2-p[3]^2*h^2)}
Exponencial=function(p,h,u){p[1]^2*exp(-p[2]^2*u-p[3]^2*h)}
#C R E S S I E - H U A N G (1999)
#sigma:desviacion estandar, a es el par?metros de escala del tiempo, b es el par?metros de escala del espacio, d es la dimensi?n espacial; a,b positivos
CH_1=function(h,u,p,d){(p[1]^2/((p[2]^2*u^2+1)^(d/2)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
CH_2=function(h,u,p,d){(p[1]^2/((p[2]*abs(u)+1)^(d/2)))*exp(-(p[3]^2*h^2)/(p[2]*abs(u)+1))}
CH_3=function(h,u,p,d){p[1]^2*((p[2]^2)*(u^2)+1)/(((p[2]^2)*(u^2)+1)^2+(p[3]^2)*h^2)^((d+1)/2)}
CH_4=function(h,u,p,d){p[1]^2*(p[2]*abs(u)+1)/((p[2]*abs(u)+1)^2+(p[3]^2)*h^2)^((d+1)/2)}
#el caso mas general de C R E S S I E - H U A N G (1999) es cuando d=2, entonces queda
CH_1=function(h,u,p){(p[1]^2/((p[2]^2*u^2+1)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
CH_2=function(h,u,p){(p[1]^2/((p[2]*abs(u)+1)))*exp(-(p[3]^2*h^2)/(p[2]*abs(u)+1))}
CH_3=function(h,u,p){p[1]^2*((p[2]^2)*(u^2)+1)/(((p[2]^2)*(u^2)+1)^2+(p[3]^2)*h^2)^((3)/2)}
CH_4=function(h,u,p){p[1]^2*(p[2]*abs(u)+1)/((p[2]*abs(u)+1)^2+(p[3]^2)*h^2)^((3)/2)}
####Gneiting (2002), combina fun1, fun2 y psi en Gneiting#####
#fun1
phi1=function(r,c,gama,v){v*exp(-c*r^gama)}                                            #c>0, 0<gama<=1, siempre v=1
phi2=function(r,c,gama,v){((2^(v-1))*gamma(v))^(-1)*(c*r^0.5)^v*besselK(c*r^0.5,v)}    #c>0, v>0
phi3=function(r,c,gama,v){(1+c*r^gama)^(-v)}                                           #c>0, 0<gama<=1, v>0
phi4=function(r,c,gama,v){gama*(2^v)*(exp(c*r^0.5)+exp(-c*r^0.5))^(-v)}                #c>0, v>0, siempre gama=1
#fun2
psi1=function(r,a,alpha,beta){(a*r^alpha+1)^beta}                                      #a>0, 0<alpha<=1, 0<=beta<=1
psi2=function(r,a,alpha,beta){log(a*r^alpha+beta)/log(beta)}                           #a>0, beta>1,  0<alpha<=1
psi3=function(r,a,alpha,beta){(a*r^alpha+beta)/(beta*(a*r^alpha+1))}                   #a>0, 0<beta<=1   0<alpha<=1  
#Cualquier combinaci?n genera una funci?n de covarianza v?lida
Gneiting=function(h,u,sigma,d,a,alpha,beta,c,gama,v,psi,phi){(sigma^2/(psi((abs(u)^2),a,alpha,beta))^(d/2))*phi(h^2/(psi(abs(u)^2,a,alpha,beta)),c,gama,v)}
#el caso mas general de Gneiting (2002) es cuando d=2, entonces queda
Gneiting=function(h,u,sigma,a,alpha,beta,c,gama,v,psi,phi){(sigma^2/(psi((abs(u)^2),a,alpha,beta)))*phi(h^2/(psi(abs(u)^2,a,alpha,beta)),c,gama,v)}
####IACO_CESSARE
C_IACO_CESSARE=function(h,u,sigma,a,b,alpha,beta,gama){(1 + (h/a)^alpha + (u/b)^beta)^(-gama)}
#(Porcu, 2007) Basado en la funci?n de supervivencia de Dagum 
#funci?n de Dagum
Dagum=function(r,lambda,theta,epsilon){1-1/(1+lambda*r^(-theta))^epsilon}                                                                                     #lamdba, theta in (0,7), epsilon in (0,7)
Dagumm=function(r,lambda,theta,epsilon){ifelse(r==0,1,Dagum(r,lambda,theta,epsilon))}

Porcu_sep=function(h,u,lambda_h,theta_h,epsilon_h,lambda_u,theta_u,epsilon_u){Dagumm(h,lambda_h,theta_h,epsilon_h)*Dagumm(u,lambda_u,theta_u,epsilon_u)}      
Porcu_Nsep=function(h,u,lambda_h,theta_h,epsilon_h,lambda_u,theta_u,epsilon_u,vartheta){vartheta*Dagumm(h,lambda_h,theta_h,epsilon_h)+(1-vartheta)*Dagumm(u,lambda_u,theta_u,epsilon_u)}

1.2 CH 1 no separable

###CH 1 no separable
library(mvtnorm)
#generar la grilla espacio temporal
x1 <- seq(0,30,by = 5)
x2 <- seq(10,60,by = 7)
t <- seq(1,20,len=10) 
grillaSpT=expand.grid(x1,x2,t)
matDistSp=as.matrix(dist(grillaSpT[,1:2]))
matDistT=as.matrix(dist(grillaSpT[,3:3]))
##parameters p, mu, que en este caso son p=c(7,2,1) y mu=120
sigma=cressie1(matDistSp,matDistT,p=c(7,2,1))
sim1=rmvnorm(1,mean=rep(120,nrow(grillaSpT)), sigma=sigma)
datos1=cbind(grillaSpT,t(sim1))
names(datos1)=c("x","y","t","z((x,y),t)")
#View(datos1)
grillaSp=expand.grid(x1,x2)
colnames(grillaSp)=c("x","y")
rownames(grillaSp)=paste("S",1:nrow(grillaSp))
datos1_ord=datos1[order(datos1$x, datos1$y, datos1$t),]
dataSim1=matrix(c(datos1_ord[,4]),nrow=length(t),ncol=nrow(grillaSp),byrow=F)
colnames(dataSim1)=rownames(grillaSp)
rownames(dataSim1)=t
write.table(dataSim1,"dataSim1.txt")

“” CH 2 no sepaarable

#CH 2 no separable
library(mvtnorm)
#generar la grilla espacio temporal 
x1 <- seq(0,30,by = 6)
x2 <- seq(10,60,by = 8)
t <- seq(1,20,len=10) 
grillaSpT=expand.grid(x1,x2,t)
matDistSp=as.matrix(dist(grillaSpT[,1:2]))
matDistT=as.matrix(dist(grillaSpT[,3:3]))
##parameters p, mu, que en este caso son p=c(7,2,1) y mu=120
sigma=CH_2(matDistSp,matDistT,p=c(10,3,4))
sim2=rmvnorm(1,mean=rep(34,nrow(grillaSpT)), sigma=sigma)
datos2=cbind(grillaSpT,t(sim2))
names(datos2)=c("x","y","t","zz((x,y),t)")
#View(datos2)
grillaSp=expand.grid(x1,x2)
colnames(grillaSp)=c("x","y")
rownames(grillaSp)=paste("S",1:nrow(grillaSp))
datos2_ord=datos2[order(datos2$x, datos2$y, datos2$t),]
dataSim2=matrix(c(datos2_ord[,4]),nrow=length(t),ncol=nrow(grillaSp),byrow=F)
colnames(dataSim2)=rownames(grillaSp)
rownames(dataSim2)=t
write.table(dataSim2,"dataSim2.txt")
class(dataSim2)
## [1] "matrix" "array"

1.3 CH3 no separable

#CH 3 no separable
x1 <- seq(0,30,by = 5)
x2 <- seq(10,60,by = 7)
grillaSp=expand.grid(x1,x2)
colnames(grillaSp)=c("x","y")
rownames(grillaSp)=paste("S",1:nrow(grillaSp))
t <- seq(1,20,len=10) 
grillaSpT=expand.grid(x1,x2,t)
matDistSp=as.matrix(dist(grillaSpT[,1:2]))
matDistT=as.matrix(dist(grillaSpT[,3:3]))
##parameters p, mu, que en este caso son p=c(7,2,1) y mu=120
sigma=CH_3(matDistSp,matDistT,p=c(6,2.5,3.2))
sim3=rmvnorm(1,mean=rep(34,nrow(grillaSpT)), sigma=sigma)
datos2=cbind(grillaSpT,t(sim3))
names(datos2)=c("x","y","t","zz((x,y),t)")
#View(datos2)
datos3 = datos2
datos3_ord=datos3[order(datos3$x, datos3$y, datos3$t),]
dataSim3=matrix(c(datos3_ord[,4]),nrow=length(t),ncol=nrow(grillaSp),byrow=F)
colnames(dataSim3)=rownames(grillaSp)
rownames(dataSim3)=t

1.4 CH 4

#caso 4
library(mvtnorm)
#generar la grilla espacio temporal
x1 <- seq(1,35,by = 7)
x2 <- seq(10,60,by = 10)
grillaSp=expand.grid(x1,x2)
colnames(grillaSp)=c("x","y")
rownames(grillaSp)=paste("S",1:nrow(grillaSp))
t <- seq(1,20,len=10) 
grillaSpT=expand.grid(x1,x2,t)
matDistSp=as.matrix(dist(grillaSpT[,1:2]))
matDistT=as.matrix(dist(grillaSpT[,3:3]))
##parameters p, mu, que en este caso son p=c(7,2,1) y mu=120
sigma=CH_3(matDistSp,matDistT,p=c(6,2.5,3.2))
sim4=rmvnorm(1,mean=rep(34,nrow(grillaSpT)), sigma=sigma)
datos4=cbind(grillaSpT,t(sim4))
names(datos4)=c("x","y","t","zz((x,y),t)")
#View(datos4)
datos4_ord=datos4[order(datos4$x, datos4$y, datos4$t),]
dataSim4=matrix(c(datos4_ord[,4]),nrow=length(t),ncol=nrow(grillaSp),byrow=F)
colnames(dataSim4)=rownames(grillaSp)
rownames(dataSim4)=t

2 Spatial modeling leukemia

2.1 Mortality

Spatial modeling of incidence and mortality childhood leukemia based on Colombian armed conflict and poverty for children born during the years 2002-2013

2.1.1 Packages Mortality

rm(list=ls())
require(rgdal)
require(pscl)
require(sf)
require(spdep)
require(spatialreg) #test.W, scores.listw
require(stringr)
require(performance)
require(AER)
require(ggplot2)
require(vcdExtra)
require(dbscan)

2.1.2 Code Mortality

  • Reading the shapefile of 1124 Colombian municipalities, defining the Coordinate Reference System and centroid and building some variables
#Reading the shapefile of 1124 Colombian municipalities
muncol <- rgdal::readOGR(dsn="Armed_Conflict_Vs_Leukemia/muncol.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/Armed_Conflict_Vs_Leukemia/muncol.shp", layer: "muncol"
## with 1124 features
## It has 17 fields
muncol=spTransform(muncol,CRS("+init=epsg:21897"))
(l <- length(muncol))
## [1] 1124
#Representative coordinate (centroid)
options(warn = -1)
xy0=data.frame(x=muncol$x,y=muncol$y)
coordinates(xy0) <- c('x','y')
proj4string(xy0) <- CRS("+init=epsg:4326")
xy0=spTransform(xy0,CRS("+init=epsg:21897"))

###Loops for avoiding NA 
r <- sum(muncol$Ndeaths)/sum(muncol$NPop)
for (i in 1:l){ 
   if(muncol$NPop[i]==0){
      muncol$EsperadosDeNCancer[i] <- 1
   }
   else{
      muncol$EsperadosDeNCancer[i] <- muncol$NPop[i]*r
   }
}

muncol$IICA_Cat=muncol$IICA_Ca
muncol$IICA_Cat=str_replace_all(muncol$IICA_Cat,"Bajo", "Low")
muncol$IICA_Cat=str_replace_all(muncol$IICA_Cat,"Medio", "Medium")
muncol$IICA_CatLow=ifelse(muncol$IICA_Cat=="Low",1,0)
muncol$IICA_CatMed=ifelse(muncol$IICA_Cat=="Medium",1,0)
muncol$IICA_High=as.character(1-(muncol$IICA_CatLow+muncol$IICA_CatMed))
muncol$UBN=muncol$NBI
  • Modeling leukemia Mortality Rate (LR) in terms of Colombian armed conflict index, poverty, rurality and health coverage. First, the usual Poisson regression model with mortality rate as response variable is estimated.
glmbaseLMR<-glm(Ndeaths ~IICA_High+UBN+Per_Rur+Cobertura+offset(log(EsperadosDeNCancer)), family = poisson,data = muncol)
anova(glmbaseLMR)
## Analysis of Deviance Table
## 
## Model: poisson, link: log
## 
## Response: Ndeaths
## 
## Terms added sequentially (first to last)
## 
## 
##           Df Deviance Resid. Df Resid. Dev
## NULL                       1123     799.92
## IICA_High  1    0.694      1122     799.22
## UBN        1   43.405      1121     755.82
## Per_Rur    1    4.017      1120     751.80
## Cobertura  1    9.185      1119     742.62
muncol$residLMR=residuals(glmbaseLMR)
summary(glmbaseLMR)
## 
## Call:
## glm(formula = Ndeaths ~ IICA_High + UBN + Per_Rur + Cobertura + 
##     offset(log(EsperadosDeNCancer)), family = poisson, data = muncol)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.9317  -0.5949  -0.4108  -0.2389   3.3300  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)   
## (Intercept) -0.583783   0.307508  -1.898  0.05764 . 
## IICA_High1   0.107822   0.084777   1.272  0.20343   
## UBN         -0.007902   0.003003  -2.632  0.00850 **
## Per_Rur     -0.002705   0.002370  -1.141  0.25380   
## Cobertura    0.991687   0.336039   2.951  0.00317 **
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 799.92  on 1123  degrees of freedom
## Residual deviance: 742.62  on 1119  degrees of freedom
## AIC: 1271.7
## 
## Number of Fisher Scoring iterations: 6
  • Rurality and conflict armed index are not statistically significant in this first auxiliar model. However, we maintain these variables in the rest of the analysis and review its significance in the final model.

  • Checking excess zeros by comparison between the number of zeros predicted by the model with the observed number of zeros. Also checking overdispersion.

mu_LMR <- predict(glmbaseLMR, type = "response")  # predict expected mean count
expLMR <- sum(dpois(x = 0, lambda = mu_LMR))      # sum the probabilities of a zero count for each mean
round(expLMR)                                    #predicted number of zeros
## [1] 898
sum(muncol$Ndeaths < 1)                          #observed number of zeros
## [1] 907
zero.test(muncol$Ndeaths)                        #score test (van den Broek, 1995)
## Score test for zero inflation
## 
##      Chi-square = 902.95398 
##      df = 1
##      pvalue: < 0.000000000000000222
##Checking overdispersion
dispersiontest(glmbaseLMR)             #Cameron & Trivedi (1990)
## 
##  Overdispersion test
## 
## data:  glmbaseLMR
## z = 2.2049, p-value = 0.01373
## alternative hypothesis: true dispersion is greater than 1
## sample estimates:
## dispersion 
##   1.109361
  • The observed frequency of zeroes in data exceeds the predicted in the Leukemia mortality rate (LMR) model. Also, overdispersion is detected.

  • Now, to validate the independence assumption, first, it is necessary to define spatial weighting possible matrices.

rook_nb_b=nb2listw(poly2nb(muncol,queen=FALSE), style="B",zero.policy = TRUE)
rook_nb_w=nb2listw(poly2nb(muncol,queen=FALSE), style="W",zero.policy = TRUE)

queen_nb_b=nb2listw(poly2nb(muncol,queen=TRUE), style="B",zero.policy = TRUE)
queen_nb_w=nb2listw(poly2nb(muncol,queen=TRUE), style="W",zero.policy = TRUE)

#Graphs neighbours
trinb=tri2nb(xy0)
options(warn = -1)
tri_nb_b=nb2listw(tri2nb(xy0), style="B",zero.policy = TRUE)
tri_nb_w=nb2listw(tri2nb(xy0), style="W",zero.policy = TRUE)

soi_nb_b=nb2listw(graph2nb(soi.graph(trinb,xy0)), style="B",zero.policy = TRUE)
soi_nb_w=nb2listw(graph2nb(soi.graph(trinb,xy0)), style="W",zero.policy = TRUE)

relative_nb_b=nb2listw(graph2nb(relativeneigh(xy0), sym=TRUE), style="B",zero.policy = TRUE)
relative_nb_w=nb2listw(graph2nb(relativeneigh(xy0), sym=TRUE), style="W",zero.policy = TRUE)

gabriel_nb_b=nb2listw(graph2nb(gabrielneigh(xy0), sym=TRUE), style="B",zero.policy = TRUE)
gabriel_nb_w=nb2listw(graph2nb(gabrielneigh(xy0), sym=TRUE), style="W",zero.policy = TRUE)

#Distance neighbours

knn1_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 1)), style="B",zero.policy = TRUE)
knn1_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 1)), style="W",zero.policy = TRUE)
knn2_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 2)), style="B",zero.policy = TRUE)
knn2_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 2)), style="W",zero.policy = TRUE)
knn3_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 3)), style="B",zero.policy = TRUE)
knn3_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 3)), style="W",zero.policy = TRUE)
knn4_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 4)), style="B",zero.policy = TRUE)
knn4_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 4)), style="W",zero.policy = TRUE)

mat=list(rook_nb_b,rook_nb_w,
         queen_nb_b,queen_nb_w,
         tri_nb_b,tri_nb_w,
         soi_nb_b,soi_nb_w,
         gabriel_nb_b,gabriel_nb_w,
         relative_nb_b,relative_nb_w,
         knn1_nb_b,knn1_nb_w,
         knn2_nb_b,knn2_nb_w,
         knn3_nb_b,knn3_nb_w,
         knn4_nb_b,knn4_nb_w)
  • Testing spatial autocorrelation using Moran index test based on weighting matrices built in the last step. Note that with all weighting matrices we obtain a significant spatial autocorrelation.
aux=numeric(0)
options(warn = -1)
{
for(i in 1:length(mat))
aux[i]=moran.test(muncol$residLMR,mat[[i]],alternative="two.sided")$"statistic"
aux
} 
##  [1] 1.238996 1.473832 1.428553 1.629968 1.367192 1.592464
##  [7] 1.921616 2.011106 1.860100 2.247294 2.629440 2.588622
## [13] 1.099401 1.099401 2.469062 2.469062 3.088200 3.088200
## [19] 3.450986 3.450986
which.max(aux)
## [1] 19
moran.test(muncol$residLMR, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  muncol$residLMR  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 3.451, p-value =
## 0.0005585
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0672352967     -0.0008904720      0.0003897053
  • First, Poisson Hurdle model is estimated without consider spatial autocorrelation.
mod.hurdleLMR <- hurdle(Ndeaths ~IICA_High+UBN+Per_Rur+Cobertura+offset(log(EsperadosDeNCancer))|IICA_High+UBN+Per_Rur+Cobertura+offset(log(EsperadosDeNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
resid_Pois_Hurdle=residuals(mod.hurdleLMR,"response")
summary(mod.hurdleLMR)
## 
## Call:
## hurdle(formula = Ndeaths ~ IICA_High + UBN + Per_Rur + 
##     Cobertura + offset(log(EsperadosDeNCancer)) | IICA_High + 
##     UBN + Per_Rur + Cobertura + offset(log(EsperadosDeNCancer)), 
##     data = muncol, dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6105 -0.4155 -0.2926 -0.1781  7.8519 
## 
## Count model coefficients (truncated poisson with log link):
##               Estimate Std. Error z value Pr(>|z|)  
## (Intercept)  0.0131708  0.3793725   0.035   0.9723  
## IICA_High1   0.2239159  0.1048208   2.136   0.0327 *
## UBN         -0.0006294  0.0050823  -0.124   0.9014  
## Per_Rur     -0.0064173  0.0049162  -1.305   0.1918  
## Cobertura    0.1702217  0.4227398   0.403   0.6872  
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -1.013658   0.570592  -1.777 0.075650 .  
## IICA_High1  -0.091317   0.177363  -0.515 0.606652    
## UBN         -0.011792   0.004690  -2.514 0.011928 *  
## Per_Rur     -0.005190   0.003982  -1.303 0.192473    
## Cobertura    2.283308   0.624231   3.658 0.000254 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 10 
## Log-likelihood:  -624 on 10 Df
pR2(mod.hurdleLMR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
##  -623.9804020 -1369.2239672  1490.4871304     0.5442817 
##          r2ML          r2CU 
##     0.7344776     0.8048896
moran.test(resid_Pois_Hurdle, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 4.8924, p-value
## = 0.0000009964
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0935041340     -0.0008904720      0.0003722701
  • Only Conflict armed index predictor is significant but model residuals are significantly spatially autocorrelated. So, we use spatial filtering and check significance again. Below we find Moran Eigenvectors.
MEpoisLMR <- spatialreg::ME(Ndeaths ~ IICA_High+UBN+Per_Rur+Cobertura+offset(log(EsperadosDeNCancer)),data=muncol,family="poisson",listw=knn4_nb_b, alpha=0.02, verbose=TRUE)
## eV[,11], I: 0.02918226 ZI: NA, pr(ZI): 0.08
MoranEigenVLMR=data.frame(fitted(MEpoisLMR))
#summary(MoranEigenVLMR)
  • Now, we used Poisson Hurdle model to manage the overdispersion due to zero excess and Moran eigenfunctions are included as additional explanatory variables, so that spatial autocorrelation is considered.
mod.hurdleLMR <- hurdle(Ndeaths ~IICA_High+UBN+Per_Rur+Cobertura+fitted(MEpoisLMR)+offset(log(EsperadosDeNCancer))|IICA_High+UBN+Per_Rur+Cobertura+offset(log(EsperadosDeNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
resid_Pois_Hurdle=residuals(mod.hurdleLMR,"response")
summary(mod.hurdleLMR)
## 
## Call:
## hurdle(formula = Ndeaths ~ IICA_High + UBN + Per_Rur + 
##     Cobertura + fitted(MEpoisLMR) + offset(log(EsperadosDeNCancer)) | 
##     IICA_High + UBN + Per_Rur + Cobertura + offset(log(EsperadosDeNCancer)), 
##     data = muncol, dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6969 -0.4153 -0.2920 -0.1791  7.8744 
## 
## Count model coefficients (truncated poisson with log link):
##                    Estimate Std. Error z value    Pr(>|z|)
## (Intercept)        0.374295   0.391853   0.955     0.33948
## IICA_High1         0.286868   0.104433   2.747     0.00602
## UBN               -0.010727   0.005917  -1.813     0.06986
## Per_Rur           -0.003464   0.005096  -0.680     0.49664
## Cobertura         -0.058726   0.436141  -0.135     0.89289
## fitted(MEpoisLMR) -8.856022   1.670191  -5.302 0.000000114
##                      
## (Intercept)          
## IICA_High1        ** 
## UBN               .  
## Per_Rur              
## Cobertura            
## fitted(MEpoisLMR) ***
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -1.013658   0.570592  -1.777 0.075650 .  
## IICA_High1  -0.091317   0.177363  -0.515 0.606652    
## UBN         -0.011792   0.004690  -2.514 0.011928 *  
## Per_Rur     -0.005190   0.003982  -1.303 0.192473    
## Cobertura    2.283308   0.624231   3.658 0.000254 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 12 
## Log-likelihood:  -610 on 11 Df
pR2(mod.hurdleLMR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
##  -610.0288758 -1369.2239672  1518.3901828     0.5544711 
##          r2ML          r2CU 
##     0.7409880     0.8120241
moran.test(resid_Pois_Hurdle, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 1.4546, p-value
## = 0.1458
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.027522708      -0.000890472       0.000381564
  • Rurality and health coverage are not statistically significant for counto model. So, those predictors are excluded of the spatial filtering and model.
MEpoisLMR <- spatialreg::ME(Ndeaths ~ IICA_High+UBN+offset(log(EsperadosDeNCancer)),data=muncol,family="poisson",listw=knn4_nb_b, alpha=0.02, verbose=TRUE)
## eV[,11], I: 0.01071212 ZI: NA, pr(ZI): 0.3
MoranEigenVLMR=data.frame(fitted(MEpoisLMR))
#summary(MoranEigenVLMR)
mod.hurdleLMR <- hurdle(Ndeaths ~IICA_High+UBN+fitted(MEpoisLMR)+offset(log(EsperadosDeNCancer))|UBN+Cobertura+offset(log(EsperadosDeNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
summary(mod.hurdleLMR)
## 
## Call:
## hurdle(formula = Ndeaths ~ IICA_High + UBN + fitted(MEpoisLMR) + 
##     offset(log(EsperadosDeNCancer)) | UBN + Cobertura + 
##     offset(log(EsperadosDeNCancer)), data = muncol, 
##     dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -1.5905 -0.4184 -0.2973 -0.1823  7.3265 
## 
## Count model coefficients (truncated poisson with log link):
##                    Estimate Std. Error z value     Pr(>|z|)
## (Intercept)        0.355460   0.097724   3.637     0.000275
## IICA_High1         0.274468   0.100011   2.744     0.006062
## UBN               -0.013803   0.003796  -3.636     0.000277
## fitted(MEpoisLMR) -9.134355   1.617421  -5.647 0.0000000163
##                      
## (Intercept)       ***
## IICA_High1        ** 
## UBN               ***
## fitted(MEpoisLMR) ***
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -1.279352   0.535993  -2.387 0.016992 *  
## UBN         -0.014391   0.004288  -3.356 0.000789 ***
## Cobertura    2.354642   0.616661   3.818 0.000134 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 11 
## Log-likelihood: -611.3 on 7 Df
pR2(mod.hurdleLMR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
##  -611.2637930 -1369.2239672  1515.9203483     0.5535692 
##          r2ML          r2CU 
##     0.7404182     0.8113997
moran.test(resid_Pois_Hurdle, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 1.4546, p-value
## = 0.1458
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.027522708      -0.000890472       0.000381564
  • Now, Poisson-Hurdle model residuals are not significant spatially autocorrelated. The LMR’s positive values depend only on the Index of armed conflict (IICA) and on the unsatisfied basic needs index (UBN) and LMR’s zero values depend on the UBN and health coverage. Note that the model shows good performance, according to pseudo R2 and the comparison between observed and predicted frequencies.
mf <- model.frame(mod.hurdleLMR)
y <- model.response(mf)
w <- model.weights(mf)
if(is.null(w)) w <- rep(1, NROW(y))
max0 <- 20L
obs <- as.vector(xtabs(w ~ factor(y, levels = 0L:max0)))
exp <- colSums(predict(mod.hurdleLMR, type = "prob", at = 0L:max0) * w)

fitted_vs_observed <- data.frame(Expected = exp,
                                 Observed = obs)
data <- reshape2::melt(fitted_vs_observed)
## No id variables; using all as measure variables
data <- data.frame(data, x =  0:20)
data1 <- data[1:21, ]
data2 <- data[22:42, ]
pMortality <- ggplot() +
  geom_line(data1, mapping = aes(x = x, y = value, group = variable
                          , color = variable)) +
  geom_point(data1, mapping = aes(x = x, y = value, group = variable,
                           color = variable)) +
  geom_col(data2, mapping = aes(x = x, y = value, group = variable),
           alpha = 0.7) +
  theme_light() +
  labs(x = "Number of deaths",
       y = "Frecuencies")
pMortality

2.2 Incidence

Spatial modeling of incidence and mortality childhood leukemia based on Colombian armed conflict and poverty for children born during the years 2002-2013

2.2.1 Packages Incidence

rm(list=ls())
require(rgdal)
require(pscl)
require(sf)
require(spdep)
require(spatialreg) #test.W, scores.listw
require(stringr)
require(performance)
require(AER)
require(ggplot2)
require(vcdExtra)

2.2.2 Code Incidence

  • Reading the shapefile of 1124 Colombian municipalities, defining the Coordinate Reference System and centroid and building some variables
#Reading the shapefile of 1124 Colombian municipalities
muncol <- rgdal::readOGR(dsn="Armed_Conflict_Vs_Leukemia/muncol.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/Armed_Conflict_Vs_Leukemia/muncol.shp", layer: "muncol"
## with 1124 features
## It has 17 fields
muncol=spTransform(muncol,CRS("+init=epsg:21897"))
(l <- length(muncol))
## [1] 1124
#Representative coordinate (centroid)
xy0=data.frame(x=muncol$x,y=muncol$y)
coordinates(xy0) <- c('x','y')
proj4string(xy0) <- CRS("+init=epsg:4326")
xy0=spTransform(xy0,CRS("+init=epsg:21897"))

###Loops for avoiding NA 
r <- sum(muncol$NCases)/sum(muncol$NPop)
for (i in 1:l){ 
   if(muncol$NPop[i]==0){
      muncol$EsperadosNCancer[i] <- 1
   }
   else{
      muncol$EsperadosNCancer[i] <- muncol$NPop[i]*r
   }
}

muncol$IICA_Cat=muncol$IICA_Ca
muncol$IICA_Cat=str_replace_all(muncol$IICA_Cat,"Bajo", "Low")
muncol$IICA_Cat=str_replace_all(muncol$IICA_Cat,"Medio", "Medium")
muncol$IICA_CatLow=ifelse(muncol$IICA_Cat=="Low",1,0)
muncol$IICA_CatMed=ifelse(muncol$IICA_Cat=="Medium",1,0)
muncol$IICA_High=as.character(1-(muncol$IICA_CatLow+muncol$IICA_CatMed))
muncol$UBN=muncol$NBI
  • Modeling leukemia Incidence Rate (LR) in terms of Colombian armed conflict index, poverty and rurality. First, the usual Poisson regression model with incidence rate as response variable is estimated.
glmbaseLR<-glm(NCases ~IICA_High+UBN+Per_Rur+offset(log(EsperadosNCancer)), family = poisson,data = muncol)
anova(glmbaseLR)
## Analysis of Deviance Table
## 
## Model: poisson, link: log
## 
## Response: NCases
## 
## Terms added sequentially (first to last)
## 
## 
##           Df Deviance Resid. Df Resid. Dev
## NULL                       1123     2524.9
## IICA_High  1     0.75      1122     2524.1
## UBN        1   328.90      1121     2195.2
## Per_Rur    1     0.11      1120     2195.1
summary(glmbaseLR)
## 
## Call:
## glm(formula = NCases ~ IICA_High + UBN + Per_Rur + offset(log(EsperadosNCancer)), 
##     family = poisson, data = muncol)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -5.1779  -1.1632  -0.5270   0.6082   7.7193  
## 
## Coefficients:
##               Estimate Std. Error z value
## (Intercept)  0.3226036  0.0276280  11.677
## IICA_High1   0.0818208  0.0294297   2.780
## UBN         -0.0123797  0.0010425 -11.875
## Per_Rur     -0.0002510  0.0007692  -0.326
##                         Pr(>|z|)    
## (Intercept) < 0.0000000000000002 ***
## IICA_High1               0.00543 ** 
## UBN         < 0.0000000000000002 ***
## Per_Rur                  0.74419    
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 2524.9  on 1123  degrees of freedom
## Residual deviance: 2195.1  on 1120  degrees of freedom
## AIC: 4174.2
## 
## Number of Fisher Scoring iterations: 5
muncol$residLR=residuals(glmbaseLR)
  • Rurality is not statistically significant in this first auxiliar model. However, we maintain this variable in the rest of the analysis and review its significance in the final model.

  • Checking excess zeros by comparison between the number of zeros predicted by the model with the observed number of zeros. Also checking overdispersion.

mu_LR <- predict(glmbaseLR, type = "response")  # predict expected mean count
expLR <- sum(dpois(x = 0, lambda = mu_LR))      # sum the probabilities of a zero count for each mean
round(expLR)                                    #predicted number of zeros
## [1] 382
sum(muncol$NCases < 1)                          #observed number of zeros
## [1] 443
zero.test(muncol$NCases)                        #score test (van den Broek, 1995)
## Score test for zero inflation
## 
##      Chi-square = 12268.7129 
##      df = 1
##      pvalue: < 0.000000000000000222
##Checking overdispersion
dispersiontest(glmbaseLR)             #Cameron & Trivedi (1990)
## 
##  Overdispersion test
## 
## data:  glmbaseLR
## z = 4.1887, p-value = 0.00001403
## alternative hypothesis: true dispersion is greater than 1
## sample estimates:
## dispersion 
##   2.309041
check_overdispersion(glmbaseLR)       #Gelman and Hill (2007)
## # Overdispersion test
## 
##        dispersion ratio =    2.431
##   Pearson's Chi-Squared = 2722.353
##                 p-value =  < 0.001
## Overdispersion detected.
  • The observed frequency of zeroes in data exceeds the predicted in the Leukemia incidence rate (LR) model. Also, overdispersion is detected.

  • Now, to validate the independence assumption, first, it is necessary to define spatial weighting possible matrices.

rook_nb_b=nb2listw(poly2nb(muncol,queen=FALSE), style="B",zero.policy = TRUE)
rook_nb_w=nb2listw(poly2nb(muncol,queen=FALSE), style="W",zero.policy = TRUE)

queen_nb_b=nb2listw(poly2nb(muncol,queen=TRUE), style="B",zero.policy = TRUE)
queen_nb_w=nb2listw(poly2nb(muncol,queen=TRUE), style="W",zero.policy = TRUE)

#Graphs neighbours
trinb=tri2nb(xy0)
options(warn = -1)
tri_nb_b=nb2listw(tri2nb(xy0), style="B",zero.policy = TRUE)
tri_nb_w=nb2listw(tri2nb(xy0), style="W",zero.policy = TRUE)

soi_nb_b=nb2listw(graph2nb(soi.graph(trinb,xy0)), style="B",zero.policy = TRUE)
soi_nb_w=nb2listw(graph2nb(soi.graph(trinb,xy0)), style="W",zero.policy = TRUE)

relative_nb_b=nb2listw(graph2nb(relativeneigh(xy0), sym=TRUE), style="B",zero.policy = TRUE)
relative_nb_w=nb2listw(graph2nb(relativeneigh(xy0), sym=TRUE), style="W",zero.policy = TRUE)

gabriel_nb_b=nb2listw(graph2nb(gabrielneigh(xy0), sym=TRUE), style="B",zero.policy = TRUE)
gabriel_nb_w=nb2listw(graph2nb(gabrielneigh(xy0), sym=TRUE), style="W",zero.policy = TRUE)

#Distance neighbours

knn1_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 1)), style="B",zero.policy = TRUE)
knn1_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 1)), style="W",zero.policy = TRUE)
knn2_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 2)), style="B",zero.policy = TRUE)
knn2_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 2)), style="W",zero.policy = TRUE)
knn3_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 3)), style="B",zero.policy = TRUE)
knn3_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 3)), style="W",zero.policy = TRUE)
knn4_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 4)), style="B",zero.policy = TRUE)
knn4_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 4)), style="W",zero.policy = TRUE)
knn6_nb_b=nb2listw(knn2nb(knearneigh(xy0, k = 6)), style="B",zero.policy = TRUE)
knn6_nb_w=nb2listw(knn2nb(knearneigh(xy0, k = 6)), style="W",zero.policy = TRUE)

mat=list(rook_nb_b,rook_nb_w,
         queen_nb_b,queen_nb_w,
         tri_nb_b,tri_nb_w,
         soi_nb_b,soi_nb_w,
         gabriel_nb_b,gabriel_nb_w,
         relative_nb_b,relative_nb_w,
         knn1_nb_b,knn1_nb_w,
         knn2_nb_b,knn2_nb_w,
         knn3_nb_b,knn3_nb_w,
         knn4_nb_b,knn4_nb_w,
         knn6_nb_b,knn6_nb_w)
  • Testing spatial autocorrelation using Moran index test based on weighting matrices built in the last step. Note that with all weighting matrices we obtain a significant spatial autocorrelation.
aux=numeric(0)
options(warn = -1)
{
for(i in 1:length(mat))
aux[i]=moran.test(muncol$residLR,mat[[i]],alternative="two.sided")$"p"
} 
aux
##  [1] 0.0000000017764454223 0.0000000000163053411
##  [3] 0.0000000011162954779 0.0000000000340919650
##  [5] 0.0000000002619438209 0.0000000000198490005
##  [7] 0.0000000000280007352 0.0000000000264847296
##  [9] 0.0000000000707310275 0.0000000000040680047
## [11] 0.0000000013453360945 0.0000000058676552459
## [13] 0.0006342820038119282 0.0006342820038119282
## [15] 0.0000000053378560647 0.0000000053378560647
## [17] 0.0000000000046536598 0.0000000000046536598
## [19] 0.0000000000002138542 0.0000000000002138542
## [21] 0.0000000000005932765 0.0000000000005932765
moran.test(muncol$residLR, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  muncol$residLR  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 3.4165, p-value
## = 0.0006343
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.123653792      -0.000890472       0.001328865
  • First, Poisson Hurdle model is estimated without consider spatial autocorrelation.
mod.hurdleLR <- hurdle(NCases ~IICA_High+UBN+Per_Rur+offset(log(EsperadosNCancer))|IICA_High+UBN+Per_Rur+offset(log(EsperadosNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
resid_Pois_Hurdle=residuals(mod.hurdleLR,"response")
summary(mod.hurdleLR)
## 
## Call:
## hurdle(formula = NCases ~ IICA_High + UBN + Per_Rur + 
##     offset(log(EsperadosNCancer)) | IICA_High + UBN + 
##     Per_Rur + offset(log(EsperadosNCancer)), data = muncol, 
##     dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6935 -0.7943 -0.3775  0.6266 17.7799 
## 
## Count model coefficients (truncated poisson with log link):
##               Estimate Std. Error z value
## (Intercept)  0.3151943  0.0289252  10.897
## IICA_High1   0.0769858  0.0309613   2.487
## UBN         -0.0123171  0.0011548 -10.666
## Per_Rur      0.0020604  0.0008876   2.321
##                        Pr(>|z|)    
## (Intercept) <0.0000000000000002 ***
## IICA_High1               0.0129 *  
## UBN         <0.0000000000000002 ***
## Per_Rur                  0.0203 *  
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value  Pr(>|z|)    
## (Intercept)  1.001514   0.249402   4.016 0.0000593 ***
## IICA_High1   0.072259   0.137921   0.524     0.600    
## UBN         -0.013830   0.003541  -3.906 0.0000939 ***
## Per_Rur     -0.004660   0.003364  -1.385     0.166    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 9 
## Log-likelihood: -2051 on 8 Df
pR2(mod.hurdleLR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
## -2051.4697559 -9229.3509481 14355.7623845     0.7777233 
##          r2ML          r2CU 
##     0.9999972     0.9999972
moran.test(resid_Pois_Hurdle, mat[[which.max(aux)]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[which.max(aux)]]    
## 
## Moran I statistic standard deviate = 4.5053, p-value
## = 0.000006627
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.158812671      -0.000890472       0.001256531
  • Thus, residuals are significantly spatially autocorrelated. So, we are going tu use spatial filtering. Below we find Moran Eigenvectors.
MEpoisLR <- spatialreg::ME(NCases ~ IICA_High+UBN+Per_Rur+offset(log(EsperadosNCancer)),data=muncol,family="poisson",listw=mat[[3]], alpha=0.02, verbose=TRUE)
## eV[,29], I: 0.01179903 ZI: NA, pr(ZI): 0.23
MoranEigenVLR=data.frame(fitted(MEpoisLR))
  • Now, we used Poisson Hurdle model to manage the overdispersion due to zero excess and Moran eigenfunctions are included as additional explanatory variables, so that spatial autocorrelation is considered.
mod.hurdleLR <- hurdle(NCases ~IICA_High+UBN+Per_Rur+fitted(MEpoisLR)+offset(log(EsperadosNCancer))|Per_Rur+offset(log(EsperadosNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
resid_Pois_Hurdle=residuals(mod.hurdleLR,"response")
moran.test(resid_Pois_Hurdle, mat[[3]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[3]]    
## 
## Moran I statistic standard deviate = 1.0424, p-value
## = 0.2972
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0162024286     -0.0008904720      0.0002689009
summary(mod.hurdleLR)
## 
## Call:
## hurdle(formula = NCases ~ IICA_High + UBN + Per_Rur + 
##     fitted(MEpoisLR) + offset(log(EsperadosNCancer)) | 
##     Per_Rur + offset(log(EsperadosNCancer)), data = muncol, 
##     dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2263 -0.7927 -0.3875  0.6339 17.8272 
## 
## Count model coefficients (truncated poisson with log link):
##                    Estimate Std. Error z value
## (Intercept)       0.2275843  0.0328678   6.924
## IICA_High1        0.1568024  0.0342051   4.584
## UBN              -0.0113328  0.0011644  -9.733
## Per_Rur           0.0016899  0.0008965   1.885
## fitted(MEpoisLR)  2.6540637  0.4767638   5.567
##                              Pr(>|z|)    
## (Intercept)          0.00000000000438 ***
## IICA_High1           0.00000455776769 ***
## UBN              < 0.0000000000000002 ***
## Per_Rur                        0.0594 .  
## fitted(MEpoisLR)     0.00000002594128 ***
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value Pr(>|z|)   
## (Intercept)  0.646903   0.213106   3.036   0.0024 **
## Per_Rur     -0.008731   0.003237  -2.697   0.0070 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 10 
## Log-likelihood: -2044 on 7 Df
pR2(mod.hurdleLR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
## -2043.6785123 -9229.3509481 14371.3448717     0.7785675 
##          r2ML          r2CU 
##     0.9999972     0.9999973
  • Rurality is not statistically significant to explain the Leukemia incidence rate. The only predictor statistically significant for zeroes model is rurality. In addition, the Spatial filtering results are the same without this variable.
MEpoisLR <- spatialreg::ME(NCases ~ IICA_High+UBN+offset(log(EsperadosNCancer)),data=muncol,family="poisson",listw=mat[[3]], alpha=0.02, verbose=TRUE)
## eV[,29], I: 0.01112525 ZI: NA, pr(ZI): 0.14
MoranEigenVLR=data.frame(fitted(MEpoisLR))
mod.hurdleLR <- hurdle(NCases ~IICA_High+UBN+fitted(MEpoisLR)+offset(log(EsperadosNCancer))|Per_Rur+offset(log(EsperadosNCancer)),data = muncol,dist = "poisson", zero.dist = "binomial")
resid_Pois_Hurdle=residuals(mod.hurdleLR,"response")
moran.test(resid_Pois_Hurdle, mat[[3]], alternative="two.sided")
## 
##  Moran I test under randomisation
## 
## data:  resid_Pois_Hurdle  
## weights: mat[[3]]    
## 
## Moran I statistic standard deviate = 1.2484, p-value
## = 0.2119
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0194478991     -0.0008904720      0.0002654261
summary(mod.hurdleLR)
## 
## Call:
## hurdle(formula = NCases ~ IICA_High + UBN + fitted(MEpoisLR) + 
##     offset(log(EsperadosNCancer)) | Per_Rur + offset(log(EsperadosNCancer)), 
##     data = muncol, dist = "poisson", zero.dist = "binomial")
## 
## Pearson residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3173 -0.7976 -0.3786  0.6607 18.2757 
## 
## Count model coefficients (truncated poisson with log link):
##                    Estimate Std. Error z value
## (Intercept)       0.2143974  0.0321264   6.674
## IICA_High1        0.1700350  0.0335266   5.072
## UBN              -0.0097928  0.0008191 -11.955
## fitted(MEpoisLR)  2.7262303  0.4759204   5.728
##                              Pr(>|z|)    
## (Intercept)            0.000000000025 ***
## IICA_High1             0.000000394376 ***
## UBN              < 0.0000000000000002 ***
## fitted(MEpoisLR)       0.000000010142 ***
## Zero hurdle model coefficients (binomial with logit link):
##              Estimate Std. Error z value Pr(>|z|)   
## (Intercept)  0.646903   0.213106   3.036   0.0024 **
## Per_Rur     -0.008731   0.003237  -2.697   0.0070 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Number of iterations in BFGS optimization: 9 
## Log-likelihood: -2045 on 6 Df
pR2(mod.hurdleLR)
## fitting null model for pseudo-r2
##           llh       llhNull            G2      McFadden 
## -2045.4283395 -9229.3509481 14367.8452173     0.7783779 
##          r2ML          r2CU 
##     0.9999972     0.9999973
  • Hence, Poisson-Hurdle model residuals are not significant spatially autocorrelated. The LR’s positive values depend only on the Index of armed conflict (IICA) and on the unsatisfied basic needs index (UBN) and its zero values depend on the rurality. Note that the model shows good performance, according to pseudo R2 and the comparison between observed and predicted frequencies.
mf <- model.frame(mod.hurdleLR)
y <- model.response(mf)
w <- model.weights(mf)
if(is.null(w)) w <- rep(1, NROW(y))
max0 <- 20L
obs <- as.vector(xtabs(w ~ factor(y, levels = 0L:max0)))
exp <- colSums(predict(mod.hurdleLR, type = "prob", at = 0L:max0) * w)

fitted_vs_observed <- data.frame(Expected = exp,
                                 Observed = obs)
data <- reshape2::melt(fitted_vs_observed)
## No id variables; using all as measure variables
data <- data.frame(data, x =  0:20)
data1 <- data[1:21, ]
data2 <- data[22:42, ]
pl1 <- ggplot() +
  geom_line(data1, mapping = aes(x = x, y = value, group = variable
                          , color = variable)) +
  geom_point(data1, mapping = aes(x = x, y = value, group = variable,
                           color = variable)) +
  geom_col(data2, mapping = aes(x = x, y = value, group = variable),
           alpha = 0.7) +
  theme_light() +
  labs(x = "Number of cases",
       y = "Frecuencies")
pl1

3 Modelos de regresión espacial

3.1 Estudio de Mercadeo

Se comparan varios tipos de modelos de regresión espacial para ver con cual se obtiene el mejor ajuste. Se consideran modelos autoregresivos y de medias móvviles así como su combinación.

3.2 Paquetes

rm(list=ls())
library(openxlsx)
library(dplyr)
library(rgdal)
library(maptools)
library(GISTools)
library(spdep)
library(readr)
library(car)
library(readxl)
library(psych)
library(rgdal)
library(FactoClass)
library(spdep)
require("GWmodel")
library("mapsRinteractive")
options(scipen = 999)

3.3 Lectura de Datos

# Lectura de Datos
BASE <- read_excel("Trabajo Grado/BASE.xlsx")
# Lectura del Shape de Colombia por Departamentos
Colombia = readOGR(dsn = "Trabajo Grado/Geodatabase Colombia", layer = "departamentos")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/Trabajo Grado/Geodatabase Colombia", layer: "departamentos"
## with 33 features
## It has 6 fields
## Integer64 fields read as strings:  AñO_CREAC

3.3.1 Cruce de información y arreglo de coordenadas

4 Pre-procesamiento de datos

#Cruce de información con el shape cargado
Insumo = merge(Colombia, BASE, by.x="COD_DANE", by.y="Cod")
Insumo = subset(Insumo[c(1:31,33),])
# Conversión a Coordenadas UTM
Crs.geo = CRS("+proj=tmerc +lat_0=4.599047222222222 +lon_0=-74.08091666666667 +k=1 +x_0=1000000 +y_0=1000000 +ellps=intl +towgs84=307,304,-318,0,0,0,0 +units=m +no_defs")  
proj4string(Insumo) <- Crs.geo 
Insumo.utm = spTransform(Insumo, CRS("+init=epsg:3724 +units=km"))

4.1 Matriz de vecindades

#---
# MATRIZ DE VECINDADES (W)
#---
## Centroides de las Áreas
Centros = getSpPPolygonsLabptSlots(Insumo.utm)
Centroids <- SpatialPointsDataFrame(coords = Centros, data=Insumo.utm@data, 
                                    proj4string=CRS("+init=epsg:3724 +units=km"))
# Matriz de Distancias entre los Centriodes
Wdist = dist(Centros, up=T)
# Matriz W de vecindades
library(pgirmess)
library(HistogramTools)
library(strucchange)
library(spdep)
Insumo.nb = poly2nb(Insumo.utm, queen=T)
#n <- max(sapply(Insumo.nb, length))
#ll <- lapply(Insumo.nb, function(X) {
#  c(as.numeric(X), rep(0, times = n - length(X)))
#})
#out <- do.call(cbind, ll)
#Departamentos<-Insumo$Departamento
#MatW<-matrix(NA,32,32)
#for (i in 1:8) {
#  for (j in 1:32) {
#    if (out[i,j]!=0) {
#      MatW[out[i,j],j]<-1
#    } else{MatW[out[i,j],j]<-0}
#  }
#}
#for (i in 1:32) {
#  for (j in 1:32) {
#    if (is.na(MatW[i,j])) {
#      MatW[i,j]<-0
#    }
#  }
#}
#colnames(MatW)<-Departamentos
#rownames(MatW)<-Departamentos
#MatW1<-MatW[,1:16]
#MatW2<-MatW[,17:32]
# Martiz W (Estilos)
Insumo.lw = nb2listw(Insumo.nb)
Insumo.lwb = nb2listw(Insumo.nb, style="B")
Insumo.lwc = nb2listw(Insumo.nb, style="C")
Insumo.lwu = nb2listw(Insumo.nb, style="U")
Insumo.lww = nb2listw(Insumo.nb, style="W")

4.2 Mapa de valores observados

#  Mapa de Valores Observados
#dev.new() #windows()
choropleth(Insumo, Insumo$CAP_BAC)
shad = auto.shading(Insumo$CAP_BAC, n=5, cols=(brewer.pal(5,"Reds")), cutter = quantileCuts)
choro.legend(1555874,535165.5, shad, fmt="%1.1f", title = "Valores Locales", cex=0.7, under = "Menos de", between = "a", over = "Mas de")
title("Valores Observados para las captaciones del banco agrario 
       en Colombia, cuarto trimestre 2020", cex.main=1)
map.scale(755874,335165.5, 250000, "km", 2, 50, sfcol='brown')

4.3 Pruebas de Autocorrelación

#----------------------------
#  PRUEBAS DE AUTOCORRELACION
#----------------------------

# Moran
moran.test(Insumo$CAP_BAC, Insumo.lw)
## 
##  Moran I test under randomisation
## 
## data:  Insumo$CAP_BAC  
## weights: Insumo.lw    
## 
## Moran I statistic standard deviate = 2.0024, p-value
## = 0.02262
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.153081266      -0.032258065       0.008566935
# Dispersograma de Moran
#dev.new() #windows()
moran.plot(Insumo$CAP_BAC, Insumo.lw, labels=as.character(Insumo$Departamento), xlab="Captaciones BAC", ylab="Captaciones BAC rezagado", las=1, pch=16, cex=0.5)
legend("bottomright", legend=c("I de Moran: 0.1530", "Valor P:      0.02262"), cex=1,bg='lightgreen')
title("Dispersograma de Moran para las captaciones del banco agrario en 
los Departamentos de Colombia, cuarto trimestre 2020", cex.main=1)

# Local G
nearng = dnearneigh(coordinates(Insumo.utm), 0, 550)
Insumo.lw.g = nb2listw(nearng, style="B")

localG = localG(Insumo$CAP_BAC, Insumo.lw.g); localG
##  [1]  1.66525050  0.02608278  1.33032949  1.15892050
##  [5]  1.85852161  0.68445519  1.49486468  0.10163662
##  [9]  1.64717068  1.32714028  2.53361281  2.21899396
## [13] -0.71311540  0.50952811  1.48899277  0.81676480
## [17]  0.98434717  2.09087184  2.08725553  1.05493906
## [21]  1.32486118  2.09147517  2.16305539  1.89323276
## [25]  1.52155929  0.84992902 -1.19798594 -1.33847805
## [29]  0.29701426 -1.60300117  1.67015910  1.96543367
## attr(,"cluster")
##  [1] High Low  Low  High Low  Low  High Low  Low  High Low 
## [12] High Low  Low  Low  High High Low  Low  High Low  High
## [23] High Low  Low  Low  Low  Low  Low  Low  Low  High
## Levels: Low High
## attr(,"gstari")
## [1] FALSE
## attr(,"call")
## localG(x = Insumo$CAP_BAC, listw = Insumo.lw.g)
## attr(,"class")
## [1] "localG"
# Simulaci?n montecarlo
sim.G = matrix(0,1000,32)
for(i in 1:1000) sim.G[i,] = localG(sample(Insumo$CAP_BAC),Insumo.lw.g)
mc.pvalor.G = (colSums(sweep(sim.G,2,localG,">="))+1)/(nrow(sim.G)+1)
mc.pvalor.G
##  [1] 0.009990010 0.438561439 0.086913087 0.114885115
##  [5] 0.001998002 0.288711289 0.067932068 0.442557443
##  [9] 0.031968032 0.055944056 0.000999001 0.001998002
## [13] 0.709290709 0.303696304 0.034965035 0.235764236
## [17] 0.168831169 0.000999001 0.000999001 0.127872128
## [21] 0.090909091 0.000999001 0.004995005 0.016983017
## [25] 0.051948052 0.228771229 0.969030969 0.963036963
## [29] 0.430569431 0.994005994 0.053946054 0.000999001

4.4 Mapas

# Mapas
par(mfrow=c(1,2), mar=c(1,1,8,1)/2)
shadeg = auto.shading(localG, n=5, cols=(brewer.pal(5,"Purples")), cutter=quantileCuts)
#dev.new() #windows()
choropleth(Insumo, localG, shading=shadeg)
choro.legend(1555874,535165.5, shadeg, fmt="%1.2f", title = "G", cex=0.7, under = "Menos de", between = "a", over = "Mas de")
title("G Getis Ord Local para las captaciones del banco agrario 
       en Colombia, cuarto trimestre 2020", cex.main=1)
map.scale(755874,335165.5, 250000, "km", 2, 50, sfcol='brown')

# Mapa de P-values
#dev.new() #windows()
shadegp = shading(c(0.01,0.05,0.1), cols = (brewer.pal(4,"Spectral")))
choropleth(Insumo, mc.pvalor.G, shading=shadegp)
choro.legend(1555874,535165.5, shadegp, fmt="%1.2f", title = "P-valor de G", cex=0.7, under = "Menos de", between = "a", over = "Mas de")
title("P- Valor de G Getis Ord Local para las captaciones del banco agrario 
       en Colombia, cuarto trimestre 2020", cex.main=1)
map.scale(755874,335165.5, 250000, "km", 2, 50, sfcol='brown')

##Modelos SDEM, SDM, Manski, SARAR

####Modelos SDEM, SDM, Manski, SARAR########
#reg.eq1=CAP_BAC ~ PIB + NBI + CAP_BOG + CAP_BC + CAP_OCC + CAP_CS + Población + IPM
reg.eq1=CAP_BAC ~ PIB + NBI + CAP_BOG+CAP_BC + CAP_OCC + CAP_CS+ Población
reg1=lm(reg.eq1,data=Insumo)                                     #OLS            y=XB+e,    
reg2=lmSLX(reg.eq1,data=Insumo, Insumo.lw)                       #SLX            y=XB+WxT+e
reg3=lagsarlm(reg.eq1,data= Insumo, Insumo.lw)                   #Lag Y          y=XB+WxT+u,   u=LWu+e
reg4=errorsarlm(reg.eq1,data=Insumo, Insumo.lw)                  #Spatial Error  y=pWy+XB+e   
reg5=errorsarlm(reg.eq1, data=Insumo, Insumo.lw, etype="emixed") #SDEM Spatial Durbin Error Model y=XB+WxT+u,   u=LWu+e
reg6=lagsarlm(reg.eq1, data=Insumo,Insumo.lw, type="mixed")      #SDM Spatial Durbin Model (add lag X to SAR) y=pWy+XB+WXT+e 
reg7=sacsarlm(reg.eq1,data=Insumo, Insumo.lw, type="sacmixed")   #Manski Model: y=pWy+XB+WXT+u,   u=LWu+e (no recomendado)
reg8=sacsarlm(reg.eq1,data=Insumo,Insumo.lw, type="sac")         #SARAR o Kelejian-Prucha, Cliff-Ord, o SAC If all T=0,y=pWy+XB+u, u=LWu+e

4.5 Resumen de modelos

#Resumen de modelos
s=summary
s(reg1)#OLS
## 
## Call:
## lm(formula = reg.eq1, data = Insumo)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -276.51  -65.60   -7.76   46.60  396.20 
## 
## Coefficients:
##                 Estimate   Std. Error t value Pr(>|t|)  
## (Intercept) 148.21380364  79.80068638   1.857   0.0756 .
## PIB           0.00389642   0.00328986   1.184   0.2479  
## NBI          -1.28539812   1.73982368  -0.739   0.4672  
## CAP_BOG      -0.06643826   0.05411306  -1.228   0.2314  
## CAP_BC        0.00397406   0.00607852   0.654   0.5195  
## CAP_OCC      -0.04340185   0.02170799  -1.999   0.0570 .
## CAP_CS        0.47283237   0.31370238   1.507   0.1448  
## Población     0.00000137   0.00006700   0.020   0.9839  
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 141.6 on 24 degrees of freedom
## Multiple R-squared:  0.8807, Adjusted R-squared:  0.8459 
## F-statistic: 25.31 on 7 and 24 DF,  p-value: 0.000000001309
s(reg2)#SLX
## 
## Call:
## lm(formula = formula(paste("y ~ ", paste(colnames(x)[-1], collapse = "+"))), 
##     data = as.data.frame(x), weights = weights)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -201.00  -74.99   -0.51   34.55  342.00 
## 
## Coefficients:
##                   Estimate   Std. Error t value Pr(>|t|)
## (Intercept)   392.97159157 284.42668099   1.382    0.185
## PIB             0.00429319   0.00383973   1.118    0.279
## NBI            -0.57603773   2.48213535  -0.232    0.819
## CAP_BOG        -0.00703635   0.07700761  -0.091    0.928
## CAP_BC         -0.00075536   0.01003615  -0.075    0.941
## CAP_OCC        -0.05372016   0.03418522  -1.571    0.135
## CAP_CS          0.12199794   0.43670734   0.279    0.783
## Población       0.00004753   0.00012149   0.391    0.701
## lag.PIB         0.00317318   0.00943185   0.336    0.741
## lag.NBI        -6.81433196   5.99552430  -1.137    0.271
## lag.CAP_BOG    -0.06868663   0.18842513  -0.365    0.720
## lag.CAP_BC      0.00684589   0.01472675   0.465    0.648
## lag.CAP_OCC    -0.00984285   0.05447122  -0.181    0.859
## lag.CAP_CS      0.33585267   1.09533771   0.307    0.763
## lag.Población  -0.00016927   0.00017459  -0.970    0.346
## 
## Residual standard error: 151.6 on 17 degrees of freedom
## Multiple R-squared:  0.9031, Adjusted R-squared:  0.8234 
## F-statistic: 11.32 on 14 and 17 DF,  p-value: 0.000005467
s(reg3)#Lag Y
## 
## Call:
## lagsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -213.859  -60.238  -17.811   42.960  393.389 
## 
## Type: lag 
## Coefficients: (numerical Hessian approximate standard errors) 
##                   Estimate     Std. Error z value Pr(>|z|)
## (Intercept) 77.75431737089 74.33304193262  1.0460  0.29555
## PIB          0.00330780479  0.00157831647  2.0958  0.03610
## NBI         -0.77863469452  1.48478285166 -0.5244  0.59999
## CAP_BOG     -0.05466121822  0.04352388108 -1.2559  0.20916
## CAP_BC       0.00533211204  0.00466472729  1.1431  0.25301
## CAP_OCC     -0.03421667740  0.01731007390 -1.9767  0.04808
## CAP_CS       0.40699816555  0.26036918467  1.5632  0.11802
## Población    0.00000091508            NaN     NaN      NaN
## 
## Rho: 0.22884, LR test value: 2.096, p-value: 0.14768
## Approximate (numerical Hessian) standard error: 0.15346
##     z-value: 1.4912, p-value: 0.1359
## Wald statistic: 2.2237, p-value: 0.1359
## 
## Log likelihood: -198.251 for lag model
## ML residual variance (sigma squared): 13916, (sigma: 117.97)
## Number of observations: 32 
## Number of parameters estimated: 10 
## AIC: 416.5, (AIC for lm: 416.6)
s(reg4)#Lag Error (SEM)
## 
## Call:
## errorsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -215.7428  -56.4299   -2.2091   46.6630  425.7867 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                 Estimate   Std. Error z value Pr(>|z|)
## (Intercept) 94.500067067 73.097738551  1.2928  0.19608
## PIB          0.003656790  0.002619923  1.3958  0.16279
## NBI         -0.334674368  1.408551018 -0.2376  0.81219
## CAP_BOG     -0.032484044  0.049990128 -0.6498  0.51582
## CAP_BC       0.001202333  0.005555428  0.2164  0.82866
## CAP_OCC     -0.048739698  0.019538015 -2.4946  0.01261
## CAP_CS       0.285572491  0.287233643  0.9942  0.32012
## Población    0.000040164  0.000066648  0.6026  0.54676
## 
## Lambda: 0.50692, LR test value: 3.8031, p-value: 0.051158
## Approximate (numerical Hessian) standard error: 0.21479
##     z-value: 2.3601, p-value: 0.018271
## Wald statistic: 5.57, p-value: 0.018271
## 
## Log likelihood: -197.3975 for error model
## ML residual variance (sigma squared): 12495, (sigma: 111.78)
## Number of observations: 32 
## Number of parameters estimated: 10 
## AIC: 414.79, (AIC for lm: 416.6)
s(reg5)#Durbin Error (SDEM)
## 
## Call:
## errorsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw, 
##     etype = "emixed")
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -199.7723  -69.8844   -2.0075   37.9235  362.9104 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                    Estimate    Std. Error z value Pr(>|z|)
## (Intercept)   248.934497490 220.997185179  1.1264  0.25999
## PIB             0.004499050   0.002763860  1.6278  0.10356
## NBI            -0.058410888   1.767448320 -0.0330  0.97364
## CAP_BOG        -0.026724643   0.054644416 -0.4891  0.62480
## CAP_BC         -0.000183348   0.007104434 -0.0258  0.97941
## CAP_OCC        -0.051006011   0.024157938 -2.1114  0.03474
## CAP_CS          0.227498808   0.309055946  0.7361  0.46166
## Población       0.000035177   0.000084525  0.4162  0.67729
## lag.PIB         0.003069904   0.007273446  0.4221  0.67297
## lag.NBI        -4.397301264   4.370216212 -1.0062  0.31432
## lag.CAP_BOG    -0.078935306   0.133353632 -0.5919  0.55390
## lag.CAP_BC      0.000970530   0.011031859  0.0880  0.92990
## lag.CAP_OCC    -0.013417109   0.040319110 -0.3328  0.73931
## lag.CAP_CS      0.374124929   0.777502427  0.4812  0.63038
## lag.Población  -0.000103911   0.000125213 -0.8299  0.40661
## 
## Lambda: 0.28217, LR test value: 0.34013, p-value: 0.55976
## Approximate (numerical Hessian) standard error: 0.43008
##     z-value: 0.6561, p-value: 0.51176
## Wald statistic: 0.43047, p-value: 0.51176
## 
## Log likelihood: -195.7931 for error model
## ML residual variance (sigma squared): 11856, (sigma: 108.89)
## Number of observations: 32 
## Number of parameters estimated: 17 
## AIC: 425.59, (AIC for lm: 423.93)
s(reg6)#Durbin (SDM)
## 
## Call:
## lagsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw, 
##     type = "mixed")
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -185.6170  -74.5630   -1.2308   34.6848  363.6597 
## 
## Type: mixed 
## Coefficients: (numerical Hessian approximate standard errors) 
##                    Estimate    Std. Error z value Pr(>|z|)
## (Intercept)   259.002911178 230.104789400  1.1256   0.2603
## PIB             0.004292096   0.002709485  1.5841   0.1132
## NBI            -0.068020334   1.599249655 -0.0425   0.9661
## CAP_BOG        -0.013498834   0.053646345 -0.2516   0.8013
## CAP_BC         -0.000674466   0.006747917 -0.1000   0.9204
## CAP_OCC        -0.052995708   0.023276623 -2.2768   0.0228
## CAP_CS          0.159111963   0.305216541  0.5213   0.6022
## Población       0.000046528   0.000083888  0.5546   0.5791
## lag.PIB         0.001006280   0.006950379  0.1448   0.8849
## lag.NBI        -5.022146095   4.504322175 -1.1150   0.2649
## lag.CAP_BOG    -0.060141057   0.129919351 -0.4629   0.6434
## lag.CAP_BC      0.003372687   0.010806814  0.3121   0.7550
## lag.CAP_OCC     0.001941495   0.030122408  0.0645   0.9486
## lag.CAP_CS      0.265435969   0.754778096  0.3517   0.7251
## lag.Población  -0.000120261   0.000126709 -0.9491   0.3426
## 
## Rho: 0.28321, LR test value: 0.99104, p-value: 0.31949
## Approximate (numerical Hessian) standard error: 0.26808
##     z-value: 1.0564, p-value: 0.29077
## Wald statistic: 1.116, p-value: 0.29077
## 
## Log likelihood: -195.4676 for mixed model
## ML residual variance (sigma squared): 11616, (sigma: 107.78)
## Number of observations: 32 
## Number of parameters estimated: 17 
## AIC: 424.94, (AIC for lm: 423.93)
s(reg7)#Manski
## 
## Call:
## sacsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw, 
##     type = "sacmixed")
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -179.6048  -72.7882   -2.7818   33.8501  346.2488 
## 
## Type: sacmixed 
## Coefficients: (numerical Hessian approximate standard errors) 
##                    Estimate    Std. Error z value Pr(>|z|)
## (Intercept)   307.899524851 284.687742330  1.0815  0.27946
## PIB             0.004070842   0.002887831  1.4097  0.15864
## NBI            -0.195254185   2.070147473 -0.0943  0.92486
## CAP_BOG         0.002531850   0.093292487  0.0271  0.97835
## CAP_BC         -0.001838769   0.009686163 -0.1898  0.84944
## CAP_OCC        -0.056119738   0.028995161 -1.9355  0.05293
## CAP_CS          0.071595235   0.518838438  0.1380  0.89025
## Población       0.000065749   0.000127955  0.5138  0.60736
## lag.PIB         0.000817609   0.006904128  0.1184  0.90573
## lag.NBI        -6.096432794   5.600016244 -1.0886  0.27631
## lag.CAP_BOG    -0.052377434   0.137793679 -0.3801  0.70386
## lag.CAP_BC      0.006801659   0.017044912  0.3990  0.68986
## lag.CAP_OCC     0.008763485   0.047596659  0.1841  0.85392
## lag.CAP_CS      0.219189297   0.801371640  0.2735  0.78446
## lag.Población  -0.000162608   0.000228334 -0.7122  0.47637
## 
## Rho: 0.38485
## Approximate (numerical Hessian) standard error: 0.37355
##     z-value: 1.0303, p-value: 0.30289
## Lambda: -0.26343
## Approximate (numerical Hessian) standard error: 0.83838
##     z-value: -0.31421, p-value: 0.75336
## 
## LR test value: 7.7816, p-value: 0.5563
## 
## Log likelihood: -195.4082 for sacmixed model
## ML residual variance (sigma squared): 11213, (sigma: 105.89)
## Number of observations: 32 
## Number of parameters estimated: 18 
## AIC: 426.82, (AIC for lm: 416.6)
s(reg8)#SARAR lag Y and lag e (SAC)
## 
## Call:
## sacsarlm(formula = reg.eq1, data = Insumo, listw = Insumo.lw, 
##     type = "sac")
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -203.1991  -58.2427   -4.1109   46.5336  421.1733 
## 
## Type: sac 
## Coefficients: (numerical Hessian approximate standard errors) 
##                 Estimate   Std. Error z value Pr(>|z|)
## (Intercept) 73.149386015 83.375351447  0.8774  0.38030
## PIB          0.003487952  0.002657617  1.3124  0.18937
## NBI         -0.337466937  1.455345658 -0.2319  0.81663
## CAP_BOG     -0.038888663  0.051472319 -0.7555  0.44993
## CAP_BC       0.002799262  0.006135570  0.4562  0.64822
## CAP_OCC     -0.043084476  0.021726659 -1.9830  0.04736
## CAP_CS       0.320438586  0.295160199  1.0856  0.27764
## Población    0.000028476  0.000068297  0.4170  0.67671
## 
## Rho: 0.1104
## Approximate (numerical Hessian) standard error: 0.19096
##     z-value: 0.57817, p-value: 0.56315
## Lambda: 0.41973
## Approximate (numerical Hessian) standard error: 0.27372
##     z-value: 1.5334, p-value: 0.12517
## 
## LR test value: 4.1193, p-value: 0.1275
## 
## Log likelihood: -197.2394 for sac model
## ML residual variance (sigma squared): 12624, (sigma: 112.36)
## Number of observations: 32 
## Number of parameters estimated: 11 
## AIC: 416.48, (AIC for lm: 416.6)

4.6 Calculo de varibles significativas

#Calculo de variables signid¿ficativas
reg.eq2=CAP_BAC ~ PIB + CAP_BOG+CAP_BC + CAP_OCC + CAP_CS+ Población
reg4=errorsarlm(reg.eq2,data=Insumo, Insumo.lw)
s(reg4)#Lag Error (SEM)
## 
## Call:
## errorsarlm(formula = reg.eq2, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -211.1287  -54.9469   -1.1316   40.5690  428.8317 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                 Estimate   Std. Error z value Pr(>|z|)
## (Intercept) 82.780380448 57.200033358  1.4472  0.14784
## PIB          0.003786089  0.002550194  1.4846  0.13764
## CAP_BOG     -0.033655761  0.049317358 -0.6824  0.49497
## CAP_BC       0.001072561  0.005563108  0.1928  0.84712
## CAP_OCC     -0.049110630  0.019547548 -2.5124  0.01199
## CAP_CS       0.290079762  0.285013021  1.0178  0.30878
## Población    0.000039933  0.000066827  0.5976  0.55013
## 
## Lambda: 0.51895, LR test value: 4.4697, p-value: 0.0345
## Approximate (numerical Hessian) standard error: 0.20433
##     z-value: 2.5398, p-value: 0.011092
## Wald statistic: 6.4505, p-value: 0.011092
## 
## Log likelihood: -197.4239 for error model
## ML residual variance (sigma squared): 12470, (sigma: 111.67)
## Number of observations: 32 
## Number of parameters estimated: 9 
## AIC: 412.85, (AIC for lm: 415.32)
reg.eq3=CAP_BAC ~ PIB + CAP_BOG + CAP_OCC + CAP_CS+ Población
reg4=errorsarlm(reg.eq3,data=Insumo, Insumo.lw)
s(reg4)#Lag Error (SEM)
## 
## Call:
## errorsarlm(formula = reg.eq3, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -214.6537  -56.5893   -1.9568   41.1618  430.2455 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                 Estimate   Std. Error z value  Pr(>|z|)
## (Intercept) 76.659389371 48.733986281  1.5730 0.1157149
## PIB          0.003936351  0.002412095  1.6319 0.1026960
## CAP_BOG     -0.026724272  0.035542537 -0.7519 0.4521139
## CAP_OCC     -0.051550780  0.014822573 -3.4779 0.0005054
## CAP_CS       0.249952777  0.204318664  1.2233 0.2211984
## Población    0.000047471  0.000055107  0.8614 0.3890008
## 
## Lambda: 0.52489, LR test value: 4.7822, p-value: 0.028756
## Approximate (numerical Hessian) standard error: 0.19905
##     z-value: 2.6369, p-value: 0.0083666
## Wald statistic: 6.9533, p-value: 0.0083666
## 
## Log likelihood: -197.4421 for error model
## ML residual variance (sigma squared): 12461, (sigma: 111.63)
## Number of observations: 32 
## Number of parameters estimated: 8 
## AIC: 410.88, (AIC for lm: 413.67)
reg.eq4=CAP_BAC ~ PIB + CAP_OCC + CAP_CS+ Población
reg4=errorsarlm(reg.eq4,data=Insumo, Insumo.lw)
s(reg4)#Lag Error (SEM)
## 
## Call:
## errorsarlm(formula = reg.eq4, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -200.4867  -63.5891   -8.8979   41.1675  444.7078 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                 Estimate   Std. Error z value  Pr(>|z|)
## (Intercept) 78.047294926 51.760316072  1.5079 0.1315904
## PIB          0.003727043  0.002409110  1.5471 0.1218483
## CAP_OCC     -0.050131489  0.014726792 -3.4041 0.0006638
## CAP_CS       0.099564078  0.037675929  2.6426 0.0082261
## Población    0.000057480  0.000053995  1.0646 0.2870778
## 
## Lambda: 0.56286, LR test value: 6.894, p-value: 0.0086485
## Approximate (numerical Hessian) standard error: 0.17902
##     z-value: 3.1441, p-value: 0.0016662
## Wald statistic: 9.8851, p-value: 0.0016662
## 
## Log likelihood: -197.7004 for error model
## ML residual variance (sigma squared): 12505, (sigma: 111.82)
## Number of observations: 32 
## Number of parameters estimated: 7 
## AIC: 409.4, (AIC for lm: 414.29)
reg.eq5=CAP_BAC ~ PIB + CAP_OCC + CAP_CS
reg4=errorsarlm(reg.eq5,data=Insumo, Insumo.lw)
s(reg4)#Lag Error (SEM)
## 
## Call:
## errorsarlm(formula = reg.eq5, data = Insumo, listw = Insumo.lw)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -189.815  -68.002  -13.434   35.002  443.595 
## 
## Type: error 
## Coefficients: (asymptotic standard errors) 
##                 Estimate   Std. Error z value
## (Intercept) 100.98166025  46.44259466  2.1743
## PIB           0.00611113   0.00092889  6.5789
## CAP_OCC      -0.04669321   0.01466331 -3.1844
## CAP_CS        0.07261035   0.02868558  2.5312
##                     Pr(>|z|)
## (Intercept)         0.029680
## PIB         0.00000000004738
## CAP_OCC             0.001451
## CAP_CS              0.011366
## 
## Lambda: 0.54225, LR test value: 6.0083, p-value: 0.014239
## Asymptotic standard error: 0.17423
##     z-value: 3.1123, p-value: 0.0018565
## Wald statistic: 9.6862, p-value: 0.0018565
## 
## Log likelihood: -198.2513 for error model
## ML residual variance (sigma squared): 13034, (sigma: 114.17)
## Number of observations: 32 
## Number of parameters estimated: 6 
## AIC: 408.5, (AIC for lm: 412.51)

4.7 Mapa Estimado

###Mapa estimado
fit = reg4$fitted.values
#dev.new() #windows()
shade.fit = shading(c(100,130,200,400), cols=(brewer.pal(5,"Reds")))
choropleth(Insumo, fit, shading=shade.fit)
choro.legend(1555874,535165.5, shade.fit, fmt="%1.2f", title = "Estimaciones", cex=0.7, under = "Menos de", between = "a", over = "Mas de")
title("Valores ajustados mediante el modelo SEM para las captaciones del banco agrario 
       en Colombia, cuarto trimestre 2020", cex.main=1)
map.scale(755874,335165.5, 250000, "km", 2, 50, sfcol='brown')

###R^2 Nagelkerke
# summary.sarlm(reg4,Nagelkerke = TRUE) TO-DO
###Test de moran residuales modelo SEM
moran.test(reg4$residuals, Insumo.lw)
## 
##  Moran I test under randomisation
## 
## data:  reg4$residuals  
## weights: Insumo.lw    
## 
## Moran I statistic standard deviate = 0.83723, p-value
## = 0.2012
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##        0.05266908       -0.03225806        0.01028984
#Municipal
ColombiaM = readOGR(dsn = "Trabajo Grado/Geodatabase Colombia", layer = "municipios")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/Trabajo Grado/Geodatabase Colombia", layer: "municipios"
## with 1107 features
## It has 6 fields
## Integer64 fields read as strings:  COD_MUN COD_DEPTO

5 Ilustración del kriging simple espacio tiempo

Martha Bohorquez

16/5/2022

5.1 librerías

library(mvtnorm)

5.2 Simulación no condicional de una realización de un campo aleatorio espacio temporal no separable usando el modelo de covarianza cressie1

En primer lugar, se generar la grilla espacio temporal. Aquí suponemos n=6 ubicaciones espaciales y T=4 momentos en el tiempo, así en total son 24 ubicaciones espacio-tiempo. Se llevará a cabo la simulación y posteriormente se usará el predictor kriging con su respectiva estimación de varianza del error de predicción, en un punto no “observado”. Se asume conocida la función de covarianza. En la práctica esta matriz se puede estimar por métodos como maxima veorsimilitud, pseudoverosimilitud y métodos basados en mínimos cuadrados.

x1 <- seq(0,3,len = 3)
x2 <- seq(1,6,len = 2)
t <- 1:4
grillaSpT=expand.grid(x1,x2,t)
#matriz de distancias (rezagos) espaciales
matDistSp=as.matrix(dist(grillaSpT[,1:2]))
#matriz de distancias (rezagos) temporales
matDistT=as.matrix(dist(grillaSpT[,3:3]))
cressie1=function(h,u,p){(p[1]^2/((p[2]^2*u^2+1)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
##parámetros p, mu, que en este caso son p=c(0.4,1.7,1.9) y mu=0
sigma=cressie1(matDistSp,matDistT,p=c(0.15,1.7,1.9))
sim1=rmvnorm(1,mean=rep(0,nrow(grillaSpT)), sigma=sigma)
datos1=cbind(grillaSpT,t(sim1))
names(datos1)=c("x","y","t","z((x,y),t)")
matDistSp
##           1        2        3        4        5        6
## 1  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 2  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 3  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 4  5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 5  5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 6  5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 7  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 8  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 9  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 10 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 11 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 12 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 13 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 14 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 15 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 16 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 17 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 18 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 19 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 20 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 21 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 22 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 23 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 24 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
##           7        8        9       10       11       12
## 1  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 2  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 3  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 4  5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 5  5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 6  5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 7  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 8  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 9  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 10 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 11 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 12 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 13 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 14 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 15 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 16 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 17 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 18 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 19 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 20 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 21 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 22 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 23 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 24 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
##          13       14       15       16       17       18
## 1  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 2  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 3  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 4  5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 5  5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 6  5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 7  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 8  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 9  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 10 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 11 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 12 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 13 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 14 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 15 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 16 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 17 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 18 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 19 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 20 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 21 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 22 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 23 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 24 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
##          19       20       21       22       23       24
## 1  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 2  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 3  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 4  5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 5  5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 6  5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 7  0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 8  1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 9  3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 10 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 11 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 12 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 13 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 14 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 15 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 16 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 17 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 18 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
## 19 0.000000 1.500000 3.000000 5.000000 5.220153 5.830952
## 20 1.500000 0.000000 1.500000 5.220153 5.000000 5.220153
## 21 3.000000 1.500000 0.000000 5.830952 5.220153 5.000000
## 22 5.000000 5.220153 5.830952 0.000000 1.500000 3.000000
## 23 5.220153 5.000000 5.220153 1.500000 0.000000 1.500000
## 24 5.830952 5.220153 5.000000 3.000000 1.500000 0.000000
matDistT
##    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
## 1  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 2  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 3  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 4  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 5  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 6  0 0 0 0 0 0 1 1 1  1  1  1  2  2  2  2  2  2  3  3  3  3
## 7  1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 8  1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 9  1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 10 1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 11 1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 12 1 1 1 1 1 1 0 0 0  0  0  0  1  1  1  1  1  1  2  2  2  2
## 13 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 14 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 15 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 16 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 17 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 18 2 2 2 2 2 2 1 1 1  1  1  1  0  0  0  0  0  0  1  1  1  1
## 19 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
## 20 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
## 21 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
## 22 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
## 23 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
## 24 3 3 3 3 3 3 2 2 2  2  2  2  1  1  1  1  1  1  0  0  0  0
##    23 24
## 1   3  3
## 2   3  3
## 3   3  3
## 4   3  3
## 5   3  3
## 6   3  3
## 7   2  2
## 8   2  2
## 9   2  2
## 10  2  2
## 11  2  2
## 12  2  2
## 13  1  1
## 14  1  1
## 15  1  1
## 16  1  1
## 17  1  1
## 18  1  1
## 19  0  0
## 20  0  0
## 21  0  0
## 22  0  0
## 23  0  0
## 24  0  0
sigma
##                                                                  1
## 1  0.0224999999999999991673327315311325946822762489318847656250000
## 2  0.0000066776797753472399274865707596848807270362158305943012238
## 3  0.0000000000000001745640467031612522788968514235007086808448520
## 4  0.0000000000000000000000000000000000000000143583827581367797582
## 5  0.0000000000000000000000000000000000000000000042613636511423543
## 6  0.0000000000000000000000000000000000000000000000000000001113981
## 7  0.0057840616966580975927270102943111851345747709274291992187500
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0000013643475657859583439243233299320579021696175914257764816
## 10 0.0000000000004857106754824595982789570016222239747178193725041
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000000001145696938456985277283312171491699972437340957
## 13 0.0017914012738853503543812184517491914448328316211700439453125
## 14 0.0009382885903262112121600568848123202769784256815910339355469
## 15 0.0001348239681125494701576655875996380018477793782949447631836
## 16 0.0000013569558875775789074329515451755590049742750125005841255
## 17 0.0000007107375915439390617206211891998535179482132662087678909
## 18 0.0000001021268545377872649108357970722249508099821468931622803
## 19 0.0008330248056275453864480406984682758775306865572929382324219
## 20 0.0006166745823446492802411000866413814947009086608886718750000
## 21 0.0002501787346616134882250348514531879118294455111026763916016
## 22 0.0000294798909060135976912316729814378390983620192855596542358
## 23 0.0000218234790719545488843489344787940353853628039360046386719
## 24 0.0000088535680510412586229854886576973171941062901169061660767
##                                                        2
## 1  0.000006677679775347239927486570759684880727036215831
## 2  0.022499999999999999167332731531132594682276248931885
## 3  0.000006677679775347239927486570759684880727036215831
## 4  0.000000000000000000000000000000000000000000004261364
## 5  0.000000000000000000000000000000000000000014358382758
## 6  0.000000000000000000000000000000000000000000004261364
## 7  0.000716813114985133783066406643058599001960828900337
## 8  0.005784061696658097592727010294311185134574770927429
## 9  0.000716813114985133783066406643058599001960828900337
## 10 0.000000000000060193649468724564487920130182986752271
## 11 0.000000000000485710675482459598278957001622223974718
## 12 0.000000000000060193649468724564487920130182986752271
## 13 0.000938288590326211212160056884812320276978425681591
## 14 0.001791401273885350354381218451749191444832831621170
## 15 0.000938288590326211212160056884812320276978425681591
## 16 0.000000710737591543939061720621189199853517948213266
## 17 0.000001356955887577578907432951545175559004974275013
## 18 0.000000710737591543939061720621189199853517948213266
## 19 0.000616674582344649280241100086641381494700908660889
## 20 0.000833024805627545386448040698468275877530686557293
## 21 0.000616674582344649280241100086641381494700908660889
## 22 0.000021823479071954548884348934478794035385362803936
## 23 0.000029479890906013597691231672981437839098362019286
## 24 0.000021823479071954548884348934478794035385362803936
##                                                                  3
## 1  0.0000000000000001745640467031612522788968514235007086808448520
## 2  0.0000066776797753472399274865707596848807270362158305943012238
## 3  0.0224999999999999991673327315311325946822762489318847656250000
## 4  0.0000000000000000000000000000000000000000000000000000001113981
## 5  0.0000000000000000000000000000000000000000000042613636511423543
## 6  0.0000000000000000000000000000000000000000143583827581367797582
## 7  0.0000013643475657859583439243233299320579021696175914257764816
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0057840616966580975927270102943111851345747709274291992187500
## 10 0.0000000000000001145696938456985277283312171491699972437340957
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000004857106754824595982789570016222239747178193725041
## 13 0.0001348239681125494701576655875996380018477793782949447631836
## 14 0.0009382885903262112121600568848123202769784256815910339355469
## 15 0.0017914012738853503543812184517491914448328316211700439453125
## 16 0.0000001021268545377872649108357970722249508099821468931622803
## 17 0.0000007107375915439390617206211891998535179482132662087678909
## 18 0.0000013569558875775789074329515451755590049742750125005841255
## 19 0.0002501787346616134882250348514531879118294455111026763916016
## 20 0.0006166745823446492802411000866413814947009086608886718750000
## 21 0.0008330248056275453864480406984682758775306865572929382324219
## 22 0.0000088535680510412586229854886576973171941062901169061660767
## 23 0.0000218234790719545488843489344787940353853628039360046386719
## 24 0.0000294798909060135976912316729814378390983620192855596542358
##                                                                  4
## 1  0.0000000000000000000000000000000000000000143583827581367797582
## 2  0.0000000000000000000000000000000000000000000042613636511423543
## 3  0.0000000000000000000000000000000000000000000000000000001113981
## 4  0.0224999999999999991673327315311325946822762489318847656250000
## 5  0.0000066776797753472399274865707596848807270362158305943012238
## 6  0.0000000000000001745640467031612522788968514235007086808448520
## 7  0.0000000000004857106754824595982789570016222239747178193725041
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000000001145696938456985277283312171491699972437340957
## 10 0.0057840616966580975927270102943111851345747709274291992187500
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0000013643475657859583439243233299320579021696175914257764816
## 13 0.0000013569558875775789074329515451755590049742750125005841255
## 14 0.0000007107375915439390617206211891998535179482132662087678909
## 15 0.0000001021268545377872649108357970722249508099821468931622803
## 16 0.0017914012738853503543812184517491914448328316211700439453125
## 17 0.0009382885903262112121600568848123202769784256815910339355469
## 18 0.0001348239681125494701576655875996380018477793782949447631836
## 19 0.0000294798909060135976912316729814378390983620192855596542358
## 20 0.0000218234790719545488843489344787940353853628039360046386719
## 21 0.0000088535680510412586229854886576973171941062901169061660767
## 22 0.0008330248056275453864480406984682758775306865572929382324219
## 23 0.0006166745823446492802411000866413814947009086608886718750000
## 24 0.0002501787346616134882250348514531879118294455111026763916016
##                                                        5
## 1  0.000000000000000000000000000000000000000000004261364
## 2  0.000000000000000000000000000000000000000014358382758
## 3  0.000000000000000000000000000000000000000000004261364
## 4  0.000006677679775347239927486570759684880727036215831
## 5  0.022499999999999999167332731531132594682276248931885
## 6  0.000006677679775347239927486570759684880727036215831
## 7  0.000000000000060193649468724564487920130182986752271
## 8  0.000000000000485710675482459598278957001622223974718
## 9  0.000000000000060193649468724564487920130182986752271
## 10 0.000716813114985133783066406643058599001960828900337
## 11 0.005784061696658097592727010294311185134574770927429
## 12 0.000716813114985133783066406643058599001960828900337
## 13 0.000000710737591543939061720621189199853517948213266
## 14 0.000001356955887577578907432951545175559004974275013
## 15 0.000000710737591543939061720621189199853517948213266
## 16 0.000938288590326211212160056884812320276978425681591
## 17 0.001791401273885350354381218451749191444832831621170
## 18 0.000938288590326211212160056884812320276978425681591
## 19 0.000021823479071954548884348934478794035385362803936
## 20 0.000029479890906013597691231672981437839098362019286
## 21 0.000021823479071954548884348934478794035385362803936
## 22 0.000616674582344649280241100086641381494700908660889
## 23 0.000833024805627545386448040698468275877530686557293
## 24 0.000616674582344649280241100086641381494700908660889
##                                                                  6
## 1  0.0000000000000000000000000000000000000000000000000000001113981
## 2  0.0000000000000000000000000000000000000000000042613636511423543
## 3  0.0000000000000000000000000000000000000000143583827581367797582
## 4  0.0000000000000001745640467031612522788968514235007086808448520
## 5  0.0000066776797753472399274865707596848807270362158305943012238
## 6  0.0224999999999999991673327315311325946822762489318847656250000
## 7  0.0000000000000001145696938456985277283312171491699972437340957
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000004857106754824595982789570016222239747178193725041
## 10 0.0000013643475657859583439243233299320579021696175914257764816
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0057840616966580975927270102943111851345747709274291992187500
## 13 0.0000001021268545377872649108357970722249508099821468931622803
## 14 0.0000007107375915439390617206211891998535179482132662087678909
## 15 0.0000013569558875775789074329515451755590049742750125005841255
## 16 0.0001348239681125494701576655875996380018477793782949447631836
## 17 0.0009382885903262112121600568848123202769784256815910339355469
## 18 0.0017914012738853503543812184517491914448328316211700439453125
## 19 0.0000088535680510412586229854886576973171941062901169061660767
## 20 0.0000218234790719545488843489344787940353853628039360046386719
## 21 0.0000294798909060135976912316729814378390983620192855596542358
## 22 0.0002501787346616134882250348514531879118294455111026763916016
## 23 0.0006166745823446492802411000866413814947009086608886718750000
## 24 0.0008330248056275453864480406984682758775306865572929382324219
##                                                                  7
## 1  0.0057840616966580975927270102943111851345747709274291992187500
## 2  0.0007168131149851337830664066430585990019608289003372192382812
## 3  0.0000013643475657859583439243233299320579021696175914257764816
## 4  0.0000000000004857106754824595982789570016222239747178193725041
## 5  0.0000000000000601936494687245644879201301829867522713872138307
## 6  0.0000000000000001145696938456985277283312171491699972437340957
## 7  0.0224999999999999991673327315311325946822762489318847656250000
## 8  0.0000066776797753472399274865707596848807270362158305943012238
## 9  0.0000000000000001745640467031612522788968514235007086808448520
## 10 0.0000000000000000000000000000000000000000143583827581367797582
## 11 0.0000000000000000000000000000000000000000000042613636511423543
## 12 0.0000000000000000000000000000000000000000000000000000001113981
## 13 0.0057840616966580975927270102943111851345747709274291992187500
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0000013643475657859583439243233299320579021696175914257764816
## 16 0.0000000000004857106754824595982789570016222239747178193725041
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000000001145696938456985277283312171491699972437340957
## 19 0.0017914012738853503543812184517491914448328316211700439453125
## 20 0.0009382885903262112121600568848123202769784256815910339355469
## 21 0.0001348239681125494701576655875996380018477793782949447631836
## 22 0.0000013569558875775789074329515451755590049742750125005841255
## 23 0.0000007107375915439390617206211891998535179482132662087678909
## 24 0.0000001021268545377872649108357970722249508099821468931622803
##                                                        8
## 1  0.000716813114985133783066406643058599001960828900337
## 2  0.005784061696658097592727010294311185134574770927429
## 3  0.000716813114985133783066406643058599001960828900337
## 4  0.000000000000060193649468724564487920130182986752271
## 5  0.000000000000485710675482459598278957001622223974718
## 6  0.000000000000060193649468724564487920130182986752271
## 7  0.000006677679775347239927486570759684880727036215831
## 8  0.022499999999999999167332731531132594682276248931885
## 9  0.000006677679775347239927486570759684880727036215831
## 10 0.000000000000000000000000000000000000000000004261364
## 11 0.000000000000000000000000000000000000000014358382758
## 12 0.000000000000000000000000000000000000000000004261364
## 13 0.000716813114985133783066406643058599001960828900337
## 14 0.005784061696658097592727010294311185134574770927429
## 15 0.000716813114985133783066406643058599001960828900337
## 16 0.000000000000060193649468724564487920130182986752271
## 17 0.000000000000485710675482459598278957001622223974718
## 18 0.000000000000060193649468724564487920130182986752271
## 19 0.000938288590326211212160056884812320276978425681591
## 20 0.001791401273885350354381218451749191444832831621170
## 21 0.000938288590326211212160056884812320276978425681591
## 22 0.000000710737591543939061720621189199853517948213266
## 23 0.000001356955887577578907432951545175559004974275013
## 24 0.000000710737591543939061720621189199853517948213266
##                                                                  9
## 1  0.0000013643475657859583439243233299320579021696175914257764816
## 2  0.0007168131149851337830664066430585990019608289003372192382812
## 3  0.0057840616966580975927270102943111851345747709274291992187500
## 4  0.0000000000000001145696938456985277283312171491699972437340957
## 5  0.0000000000000601936494687245644879201301829867522713872138307
## 6  0.0000000000004857106754824595982789570016222239747178193725041
## 7  0.0000000000000001745640467031612522788968514235007086808448520
## 8  0.0000066776797753472399274865707596848807270362158305943012238
## 9  0.0224999999999999991673327315311325946822762489318847656250000
## 10 0.0000000000000000000000000000000000000000000000000000001113981
## 11 0.0000000000000000000000000000000000000000000042613636511423543
## 12 0.0000000000000000000000000000000000000000143583827581367797582
## 13 0.0000013643475657859583439243233299320579021696175914257764816
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0057840616966580975927270102943111851345747709274291992187500
## 16 0.0000000000000001145696938456985277283312171491699972437340957
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000004857106754824595982789570016222239747178193725041
## 19 0.0001348239681125494701576655875996380018477793782949447631836
## 20 0.0009382885903262112121600568848123202769784256815910339355469
## 21 0.0017914012738853503543812184517491914448328316211700439453125
## 22 0.0000001021268545377872649108357970722249508099821468931622803
## 23 0.0000007107375915439390617206211891998535179482132662087678909
## 24 0.0000013569558875775789074329515451755590049742750125005841255
##                                                                 10
## 1  0.0000000000004857106754824595982789570016222239747178193725041
## 2  0.0000000000000601936494687245644879201301829867522713872138307
## 3  0.0000000000000001145696938456985277283312171491699972437340957
## 4  0.0057840616966580975927270102943111851345747709274291992187500
## 5  0.0007168131149851337830664066430585990019608289003372192382812
## 6  0.0000013643475657859583439243233299320579021696175914257764816
## 7  0.0000000000000000000000000000000000000000143583827581367797582
## 8  0.0000000000000000000000000000000000000000000042613636511423543
## 9  0.0000000000000000000000000000000000000000000000000000001113981
## 10 0.0224999999999999991673327315311325946822762489318847656250000
## 11 0.0000066776797753472399274865707596848807270362158305943012238
## 12 0.0000000000000001745640467031612522788968514235007086808448520
## 13 0.0000000000004857106754824595982789570016222239747178193725041
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000000001145696938456985277283312171491699972437340957
## 16 0.0057840616966580975927270102943111851345747709274291992187500
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0000013643475657859583439243233299320579021696175914257764816
## 19 0.0000013569558875775789074329515451755590049742750125005841255
## 20 0.0000007107375915439390617206211891998535179482132662087678909
## 21 0.0000001021268545377872649108357970722249508099821468931622803
## 22 0.0017914012738853503543812184517491914448328316211700439453125
## 23 0.0009382885903262112121600568848123202769784256815910339355469
## 24 0.0001348239681125494701576655875996380018477793782949447631836
##                                                       11
## 1  0.000000000000060193649468724564487920130182986752271
## 2  0.000000000000485710675482459598278957001622223974718
## 3  0.000000000000060193649468724564487920130182986752271
## 4  0.000716813114985133783066406643058599001960828900337
## 5  0.005784061696658097592727010294311185134574770927429
## 6  0.000716813114985133783066406643058599001960828900337
## 7  0.000000000000000000000000000000000000000000004261364
## 8  0.000000000000000000000000000000000000000014358382758
## 9  0.000000000000000000000000000000000000000000004261364
## 10 0.000006677679775347239927486570759684880727036215831
## 11 0.022499999999999999167332731531132594682276248931885
## 12 0.000006677679775347239927486570759684880727036215831
## 13 0.000000000000060193649468724564487920130182986752271
## 14 0.000000000000485710675482459598278957001622223974718
## 15 0.000000000000060193649468724564487920130182986752271
## 16 0.000716813114985133783066406643058599001960828900337
## 17 0.005784061696658097592727010294311185134574770927429
## 18 0.000716813114985133783066406643058599001960828900337
## 19 0.000000710737591543939061720621189199853517948213266
## 20 0.000001356955887577578907432951545175559004974275013
## 21 0.000000710737591543939061720621189199853517948213266
## 22 0.000938288590326211212160056884812320276978425681591
## 23 0.001791401273885350354381218451749191444832831621170
## 24 0.000938288590326211212160056884812320276978425681591
##                                                                 12
## 1  0.0000000000000001145696938456985277283312171491699972437340957
## 2  0.0000000000000601936494687245644879201301829867522713872138307
## 3  0.0000000000004857106754824595982789570016222239747178193725041
## 4  0.0000013643475657859583439243233299320579021696175914257764816
## 5  0.0007168131149851337830664066430585990019608289003372192382812
## 6  0.0057840616966580975927270102943111851345747709274291992187500
## 7  0.0000000000000000000000000000000000000000000000000000001113981
## 8  0.0000000000000000000000000000000000000000000042613636511423543
## 9  0.0000000000000000000000000000000000000000143583827581367797582
## 10 0.0000000000000001745640467031612522788968514235007086808448520
## 11 0.0000066776797753472399274865707596848807270362158305943012238
## 12 0.0224999999999999991673327315311325946822762489318847656250000
## 13 0.0000000000000001145696938456985277283312171491699972437340957
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000004857106754824595982789570016222239747178193725041
## 16 0.0000013643475657859583439243233299320579021696175914257764816
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0057840616966580975927270102943111851345747709274291992187500
## 19 0.0000001021268545377872649108357970722249508099821468931622803
## 20 0.0000007107375915439390617206211891998535179482132662087678909
## 21 0.0000013569558875775789074329515451755590049742750125005841255
## 22 0.0001348239681125494701576655875996380018477793782949447631836
## 23 0.0009382885903262112121600568848123202769784256815910339355469
## 24 0.0017914012738853503543812184517491914448328316211700439453125
##                                                                 13
## 1  0.0017914012738853503543812184517491914448328316211700439453125
## 2  0.0009382885903262112121600568848123202769784256815910339355469
## 3  0.0001348239681125494701576655875996380018477793782949447631836
## 4  0.0000013569558875775789074329515451755590049742750125005841255
## 5  0.0000007107375915439390617206211891998535179482132662087678909
## 6  0.0000001021268545377872649108357970722249508099821468931622803
## 7  0.0057840616966580975927270102943111851345747709274291992187500
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0000013643475657859583439243233299320579021696175914257764816
## 10 0.0000000000004857106754824595982789570016222239747178193725041
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000000001145696938456985277283312171491699972437340957
## 13 0.0224999999999999991673327315311325946822762489318847656250000
## 14 0.0000066776797753472399274865707596848807270362158305943012238
## 15 0.0000000000000001745640467031612522788968514235007086808448520
## 16 0.0000000000000000000000000000000000000000143583827581367797582
## 17 0.0000000000000000000000000000000000000000000042613636511423543
## 18 0.0000000000000000000000000000000000000000000000000000001113981
## 19 0.0057840616966580975927270102943111851345747709274291992187500
## 20 0.0007168131149851337830664066430585990019608289003372192382812
## 21 0.0000013643475657859583439243233299320579021696175914257764816
## 22 0.0000000000004857106754824595982789570016222239747178193725041
## 23 0.0000000000000601936494687245644879201301829867522713872138307
## 24 0.0000000000000001145696938456985277283312171491699972437340957
##                                                       14
## 1  0.000938288590326211212160056884812320276978425681591
## 2  0.001791401273885350354381218451749191444832831621170
## 3  0.000938288590326211212160056884812320276978425681591
## 4  0.000000710737591543939061720621189199853517948213266
## 5  0.000001356955887577578907432951545175559004974275013
## 6  0.000000710737591543939061720621189199853517948213266
## 7  0.000716813114985133783066406643058599001960828900337
## 8  0.005784061696658097592727010294311185134574770927429
## 9  0.000716813114985133783066406643058599001960828900337
## 10 0.000000000000060193649468724564487920130182986752271
## 11 0.000000000000485710675482459598278957001622223974718
## 12 0.000000000000060193649468724564487920130182986752271
## 13 0.000006677679775347239927486570759684880727036215831
## 14 0.022499999999999999167332731531132594682276248931885
## 15 0.000006677679775347239927486570759684880727036215831
## 16 0.000000000000000000000000000000000000000000004261364
## 17 0.000000000000000000000000000000000000000014358382758
## 18 0.000000000000000000000000000000000000000000004261364
## 19 0.000716813114985133783066406643058599001960828900337
## 20 0.005784061696658097592727010294311185134574770927429
## 21 0.000716813114985133783066406643058599001960828900337
## 22 0.000000000000060193649468724564487920130182986752271
## 23 0.000000000000485710675482459598278957001622223974718
## 24 0.000000000000060193649468724564487920130182986752271
##                                                                 15
## 1  0.0001348239681125494701576655875996380018477793782949447631836
## 2  0.0009382885903262112121600568848123202769784256815910339355469
## 3  0.0017914012738853503543812184517491914448328316211700439453125
## 4  0.0000001021268545377872649108357970722249508099821468931622803
## 5  0.0000007107375915439390617206211891998535179482132662087678909
## 6  0.0000013569558875775789074329515451755590049742750125005841255
## 7  0.0000013643475657859583439243233299320579021696175914257764816
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0057840616966580975927270102943111851345747709274291992187500
## 10 0.0000000000000001145696938456985277283312171491699972437340957
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000004857106754824595982789570016222239747178193725041
## 13 0.0000000000000001745640467031612522788968514235007086808448520
## 14 0.0000066776797753472399274865707596848807270362158305943012238
## 15 0.0224999999999999991673327315311325946822762489318847656250000
## 16 0.0000000000000000000000000000000000000000000000000000001113981
## 17 0.0000000000000000000000000000000000000000000042613636511423543
## 18 0.0000000000000000000000000000000000000000143583827581367797582
## 19 0.0000013643475657859583439243233299320579021696175914257764816
## 20 0.0007168131149851337830664066430585990019608289003372192382812
## 21 0.0057840616966580975927270102943111851345747709274291992187500
## 22 0.0000000000000001145696938456985277283312171491699972437340957
## 23 0.0000000000000601936494687245644879201301829867522713872138307
## 24 0.0000000000004857106754824595982789570016222239747178193725041
##                                                                 16
## 1  0.0000013569558875775789074329515451755590049742750125005841255
## 2  0.0000007107375915439390617206211891998535179482132662087678909
## 3  0.0000001021268545377872649108357970722249508099821468931622803
## 4  0.0017914012738853503543812184517491914448328316211700439453125
## 5  0.0009382885903262112121600568848123202769784256815910339355469
## 6  0.0001348239681125494701576655875996380018477793782949447631836
## 7  0.0000000000004857106754824595982789570016222239747178193725041
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000000001145696938456985277283312171491699972437340957
## 10 0.0057840616966580975927270102943111851345747709274291992187500
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0000013643475657859583439243233299320579021696175914257764816
## 13 0.0000000000000000000000000000000000000000143583827581367797582
## 14 0.0000000000000000000000000000000000000000000042613636511423543
## 15 0.0000000000000000000000000000000000000000000000000000001113981
## 16 0.0224999999999999991673327315311325946822762489318847656250000
## 17 0.0000066776797753472399274865707596848807270362158305943012238
## 18 0.0000000000000001745640467031612522788968514235007086808448520
## 19 0.0000000000004857106754824595982789570016222239747178193725041
## 20 0.0000000000000601936494687245644879201301829867522713872138307
## 21 0.0000000000000001145696938456985277283312171491699972437340957
## 22 0.0057840616966580975927270102943111851345747709274291992187500
## 23 0.0007168131149851337830664066430585990019608289003372192382812
## 24 0.0000013643475657859583439243233299320579021696175914257764816
##                                                       17
## 1  0.000000710737591543939061720621189199853517948213266
## 2  0.000001356955887577578907432951545175559004974275013
## 3  0.000000710737591543939061720621189199853517948213266
## 4  0.000938288590326211212160056884812320276978425681591
## 5  0.001791401273885350354381218451749191444832831621170
## 6  0.000938288590326211212160056884812320276978425681591
## 7  0.000000000000060193649468724564487920130182986752271
## 8  0.000000000000485710675482459598278957001622223974718
## 9  0.000000000000060193649468724564487920130182986752271
## 10 0.000716813114985133783066406643058599001960828900337
## 11 0.005784061696658097592727010294311185134574770927429
## 12 0.000716813114985133783066406643058599001960828900337
## 13 0.000000000000000000000000000000000000000000004261364
## 14 0.000000000000000000000000000000000000000014358382758
## 15 0.000000000000000000000000000000000000000000004261364
## 16 0.000006677679775347239927486570759684880727036215831
## 17 0.022499999999999999167332731531132594682276248931885
## 18 0.000006677679775347239927486570759684880727036215831
## 19 0.000000000000060193649468724564487920130182986752271
## 20 0.000000000000485710675482459598278957001622223974718
## 21 0.000000000000060193649468724564487920130182986752271
## 22 0.000716813114985133783066406643058599001960828900337
## 23 0.005784061696658097592727010294311185134574770927429
## 24 0.000716813114985133783066406643058599001960828900337
##                                                                 18
## 1  0.0000001021268545377872649108357970722249508099821468931622803
## 2  0.0000007107375915439390617206211891998535179482132662087678909
## 3  0.0000013569558875775789074329515451755590049742750125005841255
## 4  0.0001348239681125494701576655875996380018477793782949447631836
## 5  0.0009382885903262112121600568848123202769784256815910339355469
## 6  0.0017914012738853503543812184517491914448328316211700439453125
## 7  0.0000000000000001145696938456985277283312171491699972437340957
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000004857106754824595982789570016222239747178193725041
## 10 0.0000013643475657859583439243233299320579021696175914257764816
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0057840616966580975927270102943111851345747709274291992187500
## 13 0.0000000000000000000000000000000000000000000000000000001113981
## 14 0.0000000000000000000000000000000000000000000042613636511423543
## 15 0.0000000000000000000000000000000000000000143583827581367797582
## 16 0.0000000000000001745640467031612522788968514235007086808448520
## 17 0.0000066776797753472399274865707596848807270362158305943012238
## 18 0.0224999999999999991673327315311325946822762489318847656250000
## 19 0.0000000000000001145696938456985277283312171491699972437340957
## 20 0.0000000000000601936494687245644879201301829867522713872138307
## 21 0.0000000000004857106754824595982789570016222239747178193725041
## 22 0.0000013643475657859583439243233299320579021696175914257764816
## 23 0.0007168131149851337830664066430585990019608289003372192382812
## 24 0.0057840616966580975927270102943111851345747709274291992187500
##                                                                 19
## 1  0.0008330248056275453864480406984682758775306865572929382324219
## 2  0.0006166745823446492802411000866413814947009086608886718750000
## 3  0.0002501787346616134882250348514531879118294455111026763916016
## 4  0.0000294798909060135976912316729814378390983620192855596542358
## 5  0.0000218234790719545488843489344787940353853628039360046386719
## 6  0.0000088535680510412586229854886576973171941062901169061660767
## 7  0.0017914012738853503543812184517491914448328316211700439453125
## 8  0.0009382885903262112121600568848123202769784256815910339355469
## 9  0.0001348239681125494701576655875996380018477793782949447631836
## 10 0.0000013569558875775789074329515451755590049742750125005841255
## 11 0.0000007107375915439390617206211891998535179482132662087678909
## 12 0.0000001021268545377872649108357970722249508099821468931622803
## 13 0.0057840616966580975927270102943111851345747709274291992187500
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0000013643475657859583439243233299320579021696175914257764816
## 16 0.0000000000004857106754824595982789570016222239747178193725041
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000000001145696938456985277283312171491699972437340957
## 19 0.0224999999999999991673327315311325946822762489318847656250000
## 20 0.0000066776797753472399274865707596848807270362158305943012238
## 21 0.0000000000000001745640467031612522788968514235007086808448520
## 22 0.0000000000000000000000000000000000000000143583827581367797582
## 23 0.0000000000000000000000000000000000000000000042613636511423543
## 24 0.0000000000000000000000000000000000000000000000000000001113981
##                                                       20
## 1  0.000616674582344649280241100086641381494700908660889
## 2  0.000833024805627545386448040698468275877530686557293
## 3  0.000616674582344649280241100086641381494700908660889
## 4  0.000021823479071954548884348934478794035385362803936
## 5  0.000029479890906013597691231672981437839098362019286
## 6  0.000021823479071954548884348934478794035385362803936
## 7  0.000938288590326211212160056884812320276978425681591
## 8  0.001791401273885350354381218451749191444832831621170
## 9  0.000938288590326211212160056884812320276978425681591
## 10 0.000000710737591543939061720621189199853517948213266
## 11 0.000001356955887577578907432951545175559004974275013
## 12 0.000000710737591543939061720621189199853517948213266
## 13 0.000716813114985133783066406643058599001960828900337
## 14 0.005784061696658097592727010294311185134574770927429
## 15 0.000716813114985133783066406643058599001960828900337
## 16 0.000000000000060193649468724564487920130182986752271
## 17 0.000000000000485710675482459598278957001622223974718
## 18 0.000000000000060193649468724564487920130182986752271
## 19 0.000006677679775347239927486570759684880727036215831
## 20 0.022499999999999999167332731531132594682276248931885
## 21 0.000006677679775347239927486570759684880727036215831
## 22 0.000000000000000000000000000000000000000000004261364
## 23 0.000000000000000000000000000000000000000014358382758
## 24 0.000000000000000000000000000000000000000000004261364
##                                                                 21
## 1  0.0002501787346616134882250348514531879118294455111026763916016
## 2  0.0006166745823446492802411000866413814947009086608886718750000
## 3  0.0008330248056275453864480406984682758775306865572929382324219
## 4  0.0000088535680510412586229854886576973171941062901169061660767
## 5  0.0000218234790719545488843489344787940353853628039360046386719
## 6  0.0000294798909060135976912316729814378390983620192855596542358
## 7  0.0001348239681125494701576655875996380018477793782949447631836
## 8  0.0009382885903262112121600568848123202769784256815910339355469
## 9  0.0017914012738853503543812184517491914448328316211700439453125
## 10 0.0000001021268545377872649108357970722249508099821468931622803
## 11 0.0000007107375915439390617206211891998535179482132662087678909
## 12 0.0000013569558875775789074329515451755590049742750125005841255
## 13 0.0000013643475657859583439243233299320579021696175914257764816
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0057840616966580975927270102943111851345747709274291992187500
## 16 0.0000000000000001145696938456985277283312171491699972437340957
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000004857106754824595982789570016222239747178193725041
## 19 0.0000000000000001745640467031612522788968514235007086808448520
## 20 0.0000066776797753472399274865707596848807270362158305943012238
## 21 0.0224999999999999991673327315311325946822762489318847656250000
## 22 0.0000000000000000000000000000000000000000000000000000001113981
## 23 0.0000000000000000000000000000000000000000000042613636511423543
## 24 0.0000000000000000000000000000000000000000143583827581367797582
##                                                                 22
## 1  0.0000294798909060135976912316729814378390983620192855596542358
## 2  0.0000218234790719545488843489344787940353853628039360046386719
## 3  0.0000088535680510412586229854886576973171941062901169061660767
## 4  0.0008330248056275453864480406984682758775306865572929382324219
## 5  0.0006166745823446492802411000866413814947009086608886718750000
## 6  0.0002501787346616134882250348514531879118294455111026763916016
## 7  0.0000013569558875775789074329515451755590049742750125005841255
## 8  0.0000007107375915439390617206211891998535179482132662087678909
## 9  0.0000001021268545377872649108357970722249508099821468931622803
## 10 0.0017914012738853503543812184517491914448328316211700439453125
## 11 0.0009382885903262112121600568848123202769784256815910339355469
## 12 0.0001348239681125494701576655875996380018477793782949447631836
## 13 0.0000000000004857106754824595982789570016222239747178193725041
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000000001145696938456985277283312171491699972437340957
## 16 0.0057840616966580975927270102943111851345747709274291992187500
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0000013643475657859583439243233299320579021696175914257764816
## 19 0.0000000000000000000000000000000000000000143583827581367797582
## 20 0.0000000000000000000000000000000000000000000042613636511423543
## 21 0.0000000000000000000000000000000000000000000000000000001113981
## 22 0.0224999999999999991673327315311325946822762489318847656250000
## 23 0.0000066776797753472399274865707596848807270362158305943012238
## 24 0.0000000000000001745640467031612522788968514235007086808448520
##                                                       23
## 1  0.000021823479071954548884348934478794035385362803936
## 2  0.000029479890906013597691231672981437839098362019286
## 3  0.000021823479071954548884348934478794035385362803936
## 4  0.000616674582344649280241100086641381494700908660889
## 5  0.000833024805627545386448040698468275877530686557293
## 6  0.000616674582344649280241100086641381494700908660889
## 7  0.000000710737591543939061720621189199853517948213266
## 8  0.000001356955887577578907432951545175559004974275013
## 9  0.000000710737591543939061720621189199853517948213266
## 10 0.000938288590326211212160056884812320276978425681591
## 11 0.001791401273885350354381218451749191444832831621170
## 12 0.000938288590326211212160056884812320276978425681591
## 13 0.000000000000060193649468724564487920130182986752271
## 14 0.000000000000485710675482459598278957001622223974718
## 15 0.000000000000060193649468724564487920130182986752271
## 16 0.000716813114985133783066406643058599001960828900337
## 17 0.005784061696658097592727010294311185134574770927429
## 18 0.000716813114985133783066406643058599001960828900337
## 19 0.000000000000000000000000000000000000000000004261364
## 20 0.000000000000000000000000000000000000000014358382758
## 21 0.000000000000000000000000000000000000000000004261364
## 22 0.000006677679775347239927486570759684880727036215831
## 23 0.022499999999999999167332731531132594682276248931885
## 24 0.000006677679775347239927486570759684880727036215831
##                                                                 24
## 1  0.0000088535680510412586229854886576973171941062901169061660767
## 2  0.0000218234790719545488843489344787940353853628039360046386719
## 3  0.0000294798909060135976912316729814378390983620192855596542358
## 4  0.0002501787346616134882250348514531879118294455111026763916016
## 5  0.0006166745823446492802411000866413814947009086608886718750000
## 6  0.0008330248056275453864480406984682758775306865572929382324219
## 7  0.0000001021268545377872649108357970722249508099821468931622803
## 8  0.0000007107375915439390617206211891998535179482132662087678909
## 9  0.0000013569558875775789074329515451755590049742750125005841255
## 10 0.0001348239681125494701576655875996380018477793782949447631836
## 11 0.0009382885903262112121600568848123202769784256815910339355469
## 12 0.0017914012738853503543812184517491914448328316211700439453125
## 13 0.0000000000000001145696938456985277283312171491699972437340957
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000004857106754824595982789570016222239747178193725041
## 16 0.0000013643475657859583439243233299320579021696175914257764816
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0057840616966580975927270102943111851345747709274291992187500
## 19 0.0000000000000000000000000000000000000000000000000000001113981
## 20 0.0000000000000000000000000000000000000000000042613636511423543
## 21 0.0000000000000000000000000000000000000000143583827581367797582
## 22 0.0000000000000001745640467031612522788968514235007086808448520
## 23 0.0000066776797753472399274865707596848807270362158305943012238
## 24 0.0224999999999999991673327315311325946822762489318847656250000
datos1
##      x y t   z((x,y),t)
## 1  0.0 1 1 -0.197111293
## 2  1.5 1 1  0.032270503
## 3  3.0 1 1  0.199972606
## 4  0.0 6 1 -0.165773804
## 5  1.5 6 1 -0.134474031
## 6  3.0 6 1 -0.020170152
## 7  0.0 1 2 -0.093278873
## 8  1.5 1 2  0.052621834
## 9  3.0 1 2  0.298552274
## 10 0.0 6 2 -0.059641380
## 11 1.5 6 2 -0.028833549
## 12 3.0 6 2  0.024173647
## 13 0.0 1 3 -0.042869743
## 14 1.5 1 3 -0.193806283
## 15 3.0 1 3 -0.058370448
## 16 0.0 6 3 -0.023235489
## 17 1.5 6 3 -0.116042993
## 18 3.0 6 3 -0.037479098
## 19 0.0 1 4  0.006021199
## 20 1.5 1 4 -0.337476441
## 21 3.0 1 4  0.051772796
## 22 0.0 6 4 -0.085509049
## 23 1.5 6 4 -0.045540092
## 24 3.0 6 4 -0.058455223
  • Se requiere predecir predecir en el tiempo \(t=2.3\) y en el lugar \(s_0=(1.5,2.7)\). Nótese que tanto el dominio espacial como el dominio temporal con continuos y fijos. A continuación se presenta el procedimiento para llevar a cabo Kriging simple con su respectiva varianza de error de predicción estimada
grillaSpT0=rbind(expand.grid(x1,x2,t),c(1.5,2.7,2.3))
matDistSp0=as.matrix(dist(grillaSpT0[,1:2]))
matDistT0=as.matrix(dist(grillaSpT0[,3:3]))
sigma0=cressie1(matDistSp0,matDistT0,p=c(0.15,1.7,1.9))
#vector de covarianzas entre la coordenada a predecir y las observadas
sigma0
##                                                                  1
## 1  0.0224999999999999991673327315311325946822762489318847656250000
## 2  0.0000066776797753472399274865707596848807270362158305943012238
## 3  0.0000000000000001745640467031612522788968514235007086808448520
## 4  0.0000000000000000000000000000000000000000143583827581367797582
## 5  0.0000000000000000000000000000000000000000000042613636511423543
## 6  0.0000000000000000000000000000000000000000000000000000001113981
## 7  0.0057840616966580975927270102943111851345747709274291992187500
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0000013643475657859583439243233299320579021696175914257764816
## 10 0.0000000000004857106754824595982789570016222239747178193725041
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000000001145696938456985277283312171491699972437340957
## 13 0.0017914012738853503543812184517491914448328316211700439453125
## 14 0.0009382885903262112121600568848123202769784256815910339355469
## 15 0.0001348239681125494701576655875996380018477793782949447631836
## 16 0.0000013569558875775789074329515451755590049742750125005841255
## 17 0.0000007107375915439390617206211891998535179482132662087678909
## 18 0.0000001021268545377872649108357970722249508099821468931622803
## 19 0.0008330248056275453864480406984682758775306865572929382324219
## 20 0.0006166745823446492802411000866413814947009086608886718750000
## 21 0.0002501787346616134882250348514531879118294455111026763916016
## 22 0.0000294798909060135976912316729814378390983620192855596542358
## 23 0.0000218234790719545488843489344787940353853628039360046386719
## 24 0.0000088535680510412586229854886576973171941062901169061660767
## 25 0.0001632912431678741887065148263857849997293669730424880981445
##                                                        2
## 1  0.000006677679775347239927486570759684880727036215831
## 2  0.022499999999999999167332731531132594682276248931885
## 3  0.000006677679775347239927486570759684880727036215831
## 4  0.000000000000000000000000000000000000000000004261364
## 5  0.000000000000000000000000000000000000000014358382758
## 6  0.000000000000000000000000000000000000000000004261364
## 7  0.000716813114985133783066406643058599001960828900337
## 8  0.005784061696658097592727010294311185134574770927429
## 9  0.000716813114985133783066406643058599001960828900337
## 10 0.000000000000060193649468724564487920130182986752271
## 11 0.000000000000485710675482459598278957001622223974718
## 12 0.000000000000060193649468724564487920130182986752271
## 13 0.000938288590326211212160056884812320276978425681591
## 14 0.001791401273885350354381218451749191444832831621170
## 15 0.000938288590326211212160056884812320276978425681591
## 16 0.000000710737591543939061720621189199853517948213266
## 17 0.000001356955887577578907432951545175559004974275013
## 18 0.000000710737591543939061720621189199853517948213266
## 19 0.000616674582344649280241100086641381494700908660889
## 20 0.000833024805627545386448040698468275877530686557293
## 21 0.000616674582344649280241100086641381494700908660889
## 22 0.000021823479071954548884348934478794035385362803936
## 23 0.000029479890906013597691231672981437839098362019286
## 24 0.000021823479071954548884348934478794035385362803936
## 25 0.000649336057644723011438026016861613243236206471920
##                                                                  3
## 1  0.0000000000000001745640467031612522788968514235007086808448520
## 2  0.0000066776797753472399274865707596848807270362158305943012238
## 3  0.0224999999999999991673327315311325946822762489318847656250000
## 4  0.0000000000000000000000000000000000000000000000000000001113981
## 5  0.0000000000000000000000000000000000000000000042613636511423543
## 6  0.0000000000000000000000000000000000000000143583827581367797582
## 7  0.0000013643475657859583439243233299320579021696175914257764816
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0057840616966580975927270102943111851345747709274291992187500
## 10 0.0000000000000001145696938456985277283312171491699972437340957
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000004857106754824595982789570016222239747178193725041
## 13 0.0001348239681125494701576655875996380018477793782949447631836
## 14 0.0009382885903262112121600568848123202769784256815910339355469
## 15 0.0017914012738853503543812184517491914448328316211700439453125
## 16 0.0000001021268545377872649108357970722249508099821468931622803
## 17 0.0000007107375915439390617206211891998535179482132662087678909
## 18 0.0000013569558875775789074329515451755590049742750125005841255
## 19 0.0002501787346616134882250348514531879118294455111026763916016
## 20 0.0006166745823446492802411000866413814947009086608886718750000
## 21 0.0008330248056275453864480406984682758775306865572929382324219
## 22 0.0000088535680510412586229854886576973171941062901169061660767
## 23 0.0000218234790719545488843489344787940353853628039360046386719
## 24 0.0000294798909060135976912316729814378390983620192855596542358
## 25 0.0001632912431678741887065148263857849997293669730424880981445
##                                                                  4
## 1  0.0000000000000000000000000000000000000000143583827581367797582
## 2  0.0000000000000000000000000000000000000000000042613636511423543
## 3  0.0000000000000000000000000000000000000000000000000000001113981
## 4  0.0224999999999999991673327315311325946822762489318847656250000
## 5  0.0000066776797753472399274865707596848807270362158305943012238
## 6  0.0000000000000001745640467031612522788968514235007086808448520
## 7  0.0000000000004857106754824595982789570016222239747178193725041
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000000001145696938456985277283312171491699972437340957
## 10 0.0057840616966580975927270102943111851345747709274291992187500
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0000013643475657859583439243233299320579021696175914257764816
## 13 0.0000013569558875775789074329515451755590049742750125005841255
## 14 0.0000007107375915439390617206211891998535179482132662087678909
## 15 0.0000001021268545377872649108357970722249508099821468931622803
## 16 0.0017914012738853503543812184517491914448328316211700439453125
## 17 0.0009382885903262112121600568848123202769784256815910339355469
## 18 0.0001348239681125494701576655875996380018477793782949447631836
## 19 0.0000294798909060135976912316729814378390983620192855596542358
## 20 0.0000218234790719545488843489344787940353853628039360046386719
## 21 0.0000088535680510412586229854886576973171941062901169061660767
## 22 0.0008330248056275453864480406984682758775306865572929382324219
## 23 0.0006166745823446492802411000866413814947009086608886718750000
## 24 0.0002501787346616134882250348514531879118294455111026763916016
## 25 0.0000012061013013676200694398229357195972966110275592654943466
##                                                        5
## 1  0.000000000000000000000000000000000000000000004261364
## 2  0.000000000000000000000000000000000000000014358382758
## 3  0.000000000000000000000000000000000000000000004261364
## 4  0.000006677679775347239927486570759684880727036215831
## 5  0.022499999999999999167332731531132594682276248931885
## 6  0.000006677679775347239927486570759684880727036215831
## 7  0.000000000000060193649468724564487920130182986752271
## 8  0.000000000000485710675482459598278957001622223974718
## 9  0.000000000000060193649468724564487920130182986752271
## 10 0.000716813114985133783066406643058599001960828900337
## 11 0.005784061696658097592727010294311185134574770927429
## 12 0.000716813114985133783066406643058599001960828900337
## 13 0.000000710737591543939061720621189199853517948213266
## 14 0.000001356955887577578907432951545175559004974275013
## 15 0.000000710737591543939061720621189199853517948213266
## 16 0.000938288590326211212160056884812320276978425681591
## 17 0.001791401273885350354381218451749191444832831621170
## 18 0.000938288590326211212160056884812320276978425681591
## 19 0.000021823479071954548884348934478794035385362803936
## 20 0.000029479890906013597691231672981437839098362019286
## 21 0.000021823479071954548884348934478794035385362803936
## 22 0.000616674582344649280241100086641381494700908660889
## 23 0.000833024805627545386448040698468275877530686557293
## 24 0.000616674582344649280241100086641381494700908660889
## 25 0.000004796124084529605901433026160507466784110874869
##                                                                  6
## 1  0.0000000000000000000000000000000000000000000000000000001113981
## 2  0.0000000000000000000000000000000000000000000042613636511423543
## 3  0.0000000000000000000000000000000000000000143583827581367797582
## 4  0.0000000000000001745640467031612522788968514235007086808448520
## 5  0.0000066776797753472399274865707596848807270362158305943012238
## 6  0.0224999999999999991673327315311325946822762489318847656250000
## 7  0.0000000000000001145696938456985277283312171491699972437340957
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000004857106754824595982789570016222239747178193725041
## 10 0.0000013643475657859583439243233299320579021696175914257764816
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0057840616966580975927270102943111851345747709274291992187500
## 13 0.0000001021268545377872649108357970722249508099821468931622803
## 14 0.0000007107375915439390617206211891998535179482132662087678909
## 15 0.0000013569558875775789074329515451755590049742750125005841255
## 16 0.0001348239681125494701576655875996380018477793782949447631836
## 17 0.0009382885903262112121600568848123202769784256815910339355469
## 18 0.0017914012738853503543812184517491914448328316211700439453125
## 19 0.0000088535680510412586229854886576973171941062901169061660767
## 20 0.0000218234790719545488843489344787940353853628039360046386719
## 21 0.0000294798909060135976912316729814378390983620192855596542358
## 22 0.0002501787346616134882250348514531879118294455111026763916016
## 23 0.0006166745823446492802411000866413814947009086608886718750000
## 24 0.0008330248056275453864480406984682758775306865572929382324219
## 25 0.0000012061013013676200694398229357195972966110275592654943466
##                                                                  7
## 1  0.0057840616966580975927270102943111851345747709274291992187500
## 2  0.0007168131149851337830664066430585990019608289003372192382812
## 3  0.0000013643475657859583439243233299320579021696175914257764816
## 4  0.0000000000004857106754824595982789570016222239747178193725041
## 5  0.0000000000000601936494687245644879201301829867522713872138307
## 6  0.0000000000000001145696938456985277283312171491699972437340957
## 7  0.0224999999999999991673327315311325946822762489318847656250000
## 8  0.0000066776797753472399274865707596848807270362158305943012238
## 9  0.0000000000000001745640467031612522788968514235007086808448520
## 10 0.0000000000000000000000000000000000000000143583827581367797582
## 11 0.0000000000000000000000000000000000000000000042613636511423543
## 12 0.0000000000000000000000000000000000000000000000000000001113981
## 13 0.0057840616966580975927270102943111851345747709274291992187500
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0000013643475657859583439243233299320579021696175914257764816
## 16 0.0000000000004857106754824595982789570016222239747178193725041
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000000001145696938456985277283312171491699972437340957
## 19 0.0017914012738853503543812184517491914448328316211700439453125
## 20 0.0009382885903262112121600568848123202769784256815910339355469
## 21 0.0001348239681125494701576655875996380018477793782949447631836
## 22 0.0000013569558875775789074329515451755590049742750125005841255
## 23 0.0000007107375915439390617206211891998535179482132662087678909
## 24 0.0000001021268545377872649108357970722249508099821468931622803
## 25 0.0000000071885934411270752634838349332067203301122049197147135
##                                                        8
## 1  0.000716813114985133783066406643058599001960828900337
## 2  0.005784061696658097592727010294311185134574770927429
## 3  0.000716813114985133783066406643058599001960828900337
## 4  0.000000000000060193649468724564487920130182986752271
## 5  0.000000000000485710675482459598278957001622223974718
## 6  0.000000000000060193649468724564487920130182986752271
## 7  0.000006677679775347239927486570759684880727036215831
## 8  0.022499999999999999167332731531132594682276248931885
## 9  0.000006677679775347239927486570759684880727036215831
## 10 0.000000000000000000000000000000000000000000004261364
## 11 0.000000000000000000000000000000000000000014358382758
## 12 0.000000000000000000000000000000000000000000004261364
## 13 0.000716813114985133783066406643058599001960828900337
## 14 0.005784061696658097592727010294311185134574770927429
## 15 0.000716813114985133783066406643058599001960828900337
## 16 0.000000000000060193649468724564487920130182986752271
## 17 0.000000000000485710675482459598278957001622223974718
## 18 0.000000000000060193649468724564487920130182986752271
## 19 0.000938288590326211212160056884812320276978425681591
## 20 0.001791401273885350354381218451749191444832831621170
## 21 0.000938288590326211212160056884812320276978425681591
## 22 0.000000710737591543939061720621189199853517948213266
## 23 0.000001356955887577578907432951545175559004974275013
## 24 0.000000710737591543939061720621189199853517948213266
## 25 0.000004529706908199270517319159207181300530464795884
##                                                                  9
## 1  0.0000013643475657859583439243233299320579021696175914257764816
## 2  0.0007168131149851337830664066430585990019608289003372192382812
## 3  0.0057840616966580975927270102943111851345747709274291992187500
## 4  0.0000000000000001145696938456985277283312171491699972437340957
## 5  0.0000000000000601936494687245644879201301829867522713872138307
## 6  0.0000000000004857106754824595982789570016222239747178193725041
## 7  0.0000000000000001745640467031612522788968514235007086808448520
## 8  0.0000066776797753472399274865707596848807270362158305943012238
## 9  0.0224999999999999991673327315311325946822762489318847656250000
## 10 0.0000000000000000000000000000000000000000000000000000001113981
## 11 0.0000000000000000000000000000000000000000000042613636511423543
## 12 0.0000000000000000000000000000000000000000143583827581367797582
## 13 0.0000013643475657859583439243233299320579021696175914257764816
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0057840616966580975927270102943111851345747709274291992187500
## 16 0.0000000000000001145696938456985277283312171491699972437340957
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000004857106754824595982789570016222239747178193725041
## 19 0.0001348239681125494701576655875996380018477793782949447631836
## 20 0.0009382885903262112121600568848123202769784256815910339355469
## 21 0.0017914012738853503543812184517491914448328316211700439453125
## 22 0.0000001021268545377872649108357970722249508099821468931622803
## 23 0.0000007107375915439390617206211891998535179482132662087678909
## 24 0.0000013569558875775789074329515451755590049742750125005841255
## 25 0.0000000071885934411270752634838349332067203301122049197147135
##                                                                 10
## 1  0.0000000000004857106754824595982789570016222239747178193725041
## 2  0.0000000000000601936494687245644879201301829867522713872138307
## 3  0.0000000000000001145696938456985277283312171491699972437340957
## 4  0.0057840616966580975927270102943111851345747709274291992187500
## 5  0.0007168131149851337830664066430585990019608289003372192382812
## 6  0.0000013643475657859583439243233299320579021696175914257764816
## 7  0.0000000000000000000000000000000000000000143583827581367797582
## 8  0.0000000000000000000000000000000000000000000042613636511423543
## 9  0.0000000000000000000000000000000000000000000000000000001113981
## 10 0.0224999999999999991673327315311325946822762489318847656250000
## 11 0.0000066776797753472399274865707596848807270362158305943012238
## 12 0.0000000000000001745640467031612522788968514235007086808448520
## 13 0.0000000000004857106754824595982789570016222239747178193725041
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000000001145696938456985277283312171491699972437340957
## 16 0.0057840616966580975927270102943111851345747709274291992187500
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0000013643475657859583439243233299320579021696175914257764816
## 19 0.0000013569558875775789074329515451755590049742750125005841255
## 20 0.0000007107375915439390617206211891998535179482132662087678909
## 21 0.0000001021268545377872649108357970722249508099821468931622803
## 22 0.0017914012738853503543812184517491914448328316211700439453125
## 23 0.0009382885903262112121600568848123202769784256815910339355469
## 24 0.0001348239681125494701576655875996380018477793782949447631836
## 25 0.0000000000000000008000711605775138903917974564434023496189163
##                                                       11
## 1  0.000000000000060193649468724564487920130182986752271
## 2  0.000000000000485710675482459598278957001622223974718
## 3  0.000000000000060193649468724564487920130182986752271
## 4  0.000716813114985133783066406643058599001960828900337
## 5  0.005784061696658097592727010294311185134574770927429
## 6  0.000716813114985133783066406643058599001960828900337
## 7  0.000000000000000000000000000000000000000000004261364
## 8  0.000000000000000000000000000000000000000014358382758
## 9  0.000000000000000000000000000000000000000000004261364
## 10 0.000006677679775347239927486570759684880727036215831
## 11 0.022499999999999999167332731531132594682276248931885
## 12 0.000006677679775347239927486570759684880727036215831
## 13 0.000000000000060193649468724564487920130182986752271
## 14 0.000000000000485710675482459598278957001622223974718
## 15 0.000000000000060193649468724564487920130182986752271
## 16 0.000716813114985133783066406643058599001960828900337
## 17 0.005784061696658097592727010294311185134574770927429
## 18 0.000716813114985133783066406643058599001960828900337
## 19 0.000000710737591543939061720621189199853517948213266
## 20 0.000001356955887577578907432951545175559004974275013
## 21 0.000000710737591543939061720621189199853517948213266
## 22 0.000938288590326211212160056884812320276978425681591
## 23 0.001791401273885350354381218451749191444832831621170
## 24 0.000938288590326211212160056884812320276978425681591
## 25 0.000000000000000504144224151701356394133694403909602
##                                                                 12
## 1  0.0000000000000001145696938456985277283312171491699972437340957
## 2  0.0000000000000601936494687245644879201301829867522713872138307
## 3  0.0000000000004857106754824595982789570016222239747178193725041
## 4  0.0000013643475657859583439243233299320579021696175914257764816
## 5  0.0007168131149851337830664066430585990019608289003372192382812
## 6  0.0057840616966580975927270102943111851345747709274291992187500
## 7  0.0000000000000000000000000000000000000000000000000000001113981
## 8  0.0000000000000000000000000000000000000000000042613636511423543
## 9  0.0000000000000000000000000000000000000000143583827581367797582
## 10 0.0000000000000001745640467031612522788968514235007086808448520
## 11 0.0000066776797753472399274865707596848807270362158305943012238
## 12 0.0224999999999999991673327315311325946822762489318847656250000
## 13 0.0000000000000001145696938456985277283312171491699972437340957
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000004857106754824595982789570016222239747178193725041
## 16 0.0000013643475657859583439243233299320579021696175914257764816
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0057840616966580975927270102943111851345747709274291992187500
## 19 0.0000001021268545377872649108357970722249508099821468931622803
## 20 0.0000007107375915439390617206211891998535179482132662087678909
## 21 0.0000013569558875775789074329515451755590049742750125005841255
## 22 0.0001348239681125494701576655875996380018477793782949447631836
## 23 0.0009382885903262112121600568848123202769784256815910339355469
## 24 0.0017914012738853503543812184517491914448328316211700439453125
## 25 0.0000000000000000008000711605775138903917974564434023496189163
##                                                                 13
## 1  0.0017914012738853503543812184517491914448328316211700439453125
## 2  0.0009382885903262112121600568848123202769784256815910339355469
## 3  0.0001348239681125494701576655875996380018477793782949447631836
## 4  0.0000013569558875775789074329515451755590049742750125005841255
## 5  0.0000007107375915439390617206211891998535179482132662087678909
## 6  0.0000001021268545377872649108357970722249508099821468931622803
## 7  0.0057840616966580975927270102943111851345747709274291992187500
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0000013643475657859583439243233299320579021696175914257764816
## 10 0.0000000000004857106754824595982789570016222239747178193725041
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000000001145696938456985277283312171491699972437340957
## 13 0.0224999999999999991673327315311325946822762489318847656250000
## 14 0.0000066776797753472399274865707596848807270362158305943012238
## 15 0.0000000000000001745640467031612522788968514235007086808448520
## 16 0.0000000000000000000000000000000000000000143583827581367797582
## 17 0.0000000000000000000000000000000000000000000042613636511423543
## 18 0.0000000000000000000000000000000000000000000000000000001113981
## 19 0.0057840616966580975927270102943111851345747709274291992187500
## 20 0.0007168131149851337830664066430585990019608289003372192382812
## 21 0.0000013643475657859583439243233299320579021696175914257764816
## 22 0.0000000000004857106754824595982789570016222239747178193725041
## 23 0.0000000000000601936494687245644879201301829867522713872138307
## 24 0.0000000000000001145696938456985277283312171491699972437340957
## 25 0.0000043025960066369215722297848769617445441326708532869815826
##                                                       14
## 1  0.000938288590326211212160056884812320276978425681591
## 2  0.001791401273885350354381218451749191444832831621170
## 3  0.000938288590326211212160056884812320276978425681591
## 4  0.000000710737591543939061720621189199853517948213266
## 5  0.000001356955887577578907432951545175559004974275013
## 6  0.000000710737591543939061720621189199853517948213266
## 7  0.000716813114985133783066406643058599001960828900337
## 8  0.005784061696658097592727010294311185134574770927429
## 9  0.000716813114985133783066406643058599001960828900337
## 10 0.000000000000060193649468724564487920130182986752271
## 11 0.000000000000485710675482459598278957001622223974718
## 12 0.000000000000060193649468724564487920130182986752271
## 13 0.000006677679775347239927486570759684880727036215831
## 14 0.022499999999999999167332731531132594682276248931885
## 15 0.000006677679775347239927486570759684880727036215831
## 16 0.000000000000000000000000000000000000000000004261364
## 17 0.000000000000000000000000000000000000000014358382758
## 18 0.000000000000000000000000000000000000000000004261364
## 19 0.000716813114985133783066406643058599001960828900337
## 20 0.005784061696658097592727010294311185134574770927429
## 21 0.000716813114985133783066406643058599001960828900337
## 22 0.000000000000060193649468724564487920130182986752271
## 23 0.000000000000485710675482459598278957001622223974718
## 24 0.000000000000060193649468724564487920130182986752271
## 25 0.000124094247233588712365018325023413581220665946603
##                                                                 15
## 1  0.0001348239681125494701576655875996380018477793782949447631836
## 2  0.0009382885903262112121600568848123202769784256815910339355469
## 3  0.0017914012738853503543812184517491914448328316211700439453125
## 4  0.0000001021268545377872649108357970722249508099821468931622803
## 5  0.0000007107375915439390617206211891998535179482132662087678909
## 6  0.0000013569558875775789074329515451755590049742750125005841255
## 7  0.0000013643475657859583439243233299320579021696175914257764816
## 8  0.0007168131149851337830664066430585990019608289003372192382812
## 9  0.0057840616966580975927270102943111851345747709274291992187500
## 10 0.0000000000000001145696938456985277283312171491699972437340957
## 11 0.0000000000000601936494687245644879201301829867522713872138307
## 12 0.0000000000004857106754824595982789570016222239747178193725041
## 13 0.0000000000000001745640467031612522788968514235007086808448520
## 14 0.0000066776797753472399274865707596848807270362158305943012238
## 15 0.0224999999999999991673327315311325946822762489318847656250000
## 16 0.0000000000000000000000000000000000000000000000000000001113981
## 17 0.0000000000000000000000000000000000000000000042613636511423543
## 18 0.0000000000000000000000000000000000000000143583827581367797582
## 19 0.0000013643475657859583439243233299320579021696175914257764816
## 20 0.0007168131149851337830664066430585990019608289003372192382812
## 21 0.0057840616966580975927270102943111851345747709274291992187500
## 22 0.0000000000000001145696938456985277283312171491699972437340957
## 23 0.0000000000000601936494687245644879201301829867522713872138307
## 24 0.0000000000004857106754824595982789570016222239747178193725041
## 25 0.0000043025960066369215722297848769617445441326708532869815826
##                                                                 16
## 1  0.0000013569558875775789074329515451755590049742750125005841255
## 2  0.0000007107375915439390617206211891998535179482132662087678909
## 3  0.0000001021268545377872649108357970722249508099821468931622803
## 4  0.0017914012738853503543812184517491914448328316211700439453125
## 5  0.0009382885903262112121600568848123202769784256815910339355469
## 6  0.0001348239681125494701576655875996380018477793782949447631836
## 7  0.0000000000004857106754824595982789570016222239747178193725041
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000000001145696938456985277283312171491699972437340957
## 10 0.0057840616966580975927270102943111851345747709274291992187500
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0000013643475657859583439243233299320579021696175914257764816
## 13 0.0000000000000000000000000000000000000000143583827581367797582
## 14 0.0000000000000000000000000000000000000000000042613636511423543
## 15 0.0000000000000000000000000000000000000000000000000000001113981
## 16 0.0224999999999999991673327315311325946822762489318847656250000
## 17 0.0000066776797753472399274865707596848807270362158305943012238
## 18 0.0000000000000001745640467031612522788968514235007086808448520
## 19 0.0000000000004857106754824595982789570016222239747178193725041
## 20 0.0000000000000601936494687245644879201301829867522713872138307
## 21 0.0000000000000001145696938456985277283312171491699972437340957
## 22 0.0057840616966580975927270102943111851345747709274291992187500
## 23 0.0007168131149851337830664066430585990019608289003372192382812
## 24 0.0000013643475657859583439243233299320579021696175914257764816
## 25 0.0000000000277041296343146712529251226977817482328980691619336
##                                                       17
## 1  0.000000710737591543939061720621189199853517948213266
## 2  0.000001356955887577578907432951545175559004974275013
## 3  0.000000710737591543939061720621189199853517948213266
## 4  0.000938288590326211212160056884812320276978425681591
## 5  0.001791401273885350354381218451749191444832831621170
## 6  0.000938288590326211212160056884812320276978425681591
## 7  0.000000000000060193649468724564487920130182986752271
## 8  0.000000000000485710675482459598278957001622223974718
## 9  0.000000000000060193649468724564487920130182986752271
## 10 0.000716813114985133783066406643058599001960828900337
## 11 0.005784061696658097592727010294311185134574770927429
## 12 0.000716813114985133783066406643058599001960828900337
## 13 0.000000000000000000000000000000000000000000004261364
## 14 0.000000000000000000000000000000000000000014358382758
## 15 0.000000000000000000000000000000000000000000004261364
## 16 0.000006677679775347239927486570759684880727036215831
## 17 0.022499999999999999167332731531132594682276248931885
## 18 0.000006677679775347239927486570759684880727036215831
## 19 0.000000000000060193649468724564487920130182986752271
## 20 0.000000000000485710675482459598278957001622223974718
## 21 0.000000000000060193649468724564487920130182986752271
## 22 0.000716813114985133783066406643058599001960828900337
## 23 0.005784061696658097592727010294311185134574770927429
## 24 0.000716813114985133783066406643058599001960828900337
## 25 0.000000000799034607694732358521092635550431282354111
##                                                                 18
## 1  0.0000001021268545377872649108357970722249508099821468931622803
## 2  0.0000007107375915439390617206211891998535179482132662087678909
## 3  0.0000013569558875775789074329515451755590049742750125005841255
## 4  0.0001348239681125494701576655875996380018477793782949447631836
## 5  0.0009382885903262112121600568848123202769784256815910339355469
## 6  0.0017914012738853503543812184517491914448328316211700439453125
## 7  0.0000000000000001145696938456985277283312171491699972437340957
## 8  0.0000000000000601936494687245644879201301829867522713872138307
## 9  0.0000000000004857106754824595982789570016222239747178193725041
## 10 0.0000013643475657859583439243233299320579021696175914257764816
## 11 0.0007168131149851337830664066430585990019608289003372192382812
## 12 0.0057840616966580975927270102943111851345747709274291992187500
## 13 0.0000000000000000000000000000000000000000000000000000001113981
## 14 0.0000000000000000000000000000000000000000000042613636511423543
## 15 0.0000000000000000000000000000000000000000143583827581367797582
## 16 0.0000000000000001745640467031612522788968514235007086808448520
## 17 0.0000066776797753472399274865707596848807270362158305943012238
## 18 0.0224999999999999991673327315311325946822762489318847656250000
## 19 0.0000000000000001145696938456985277283312171491699972437340957
## 20 0.0000000000000601936494687245644879201301829867522713872138307
## 21 0.0000000000004857106754824595982789570016222239747178193725041
## 22 0.0000013643475657859583439243233299320579021696175914257764816
## 23 0.0007168131149851337830664066430585990019608289003372192382812
## 24 0.0057840616966580975927270102943111851345747709274291992187500
## 25 0.0000000000277041296343146712529251226977817482328980691619336
##                                                                 19
## 1  0.0008330248056275453864480406984682758775306865572929382324219
## 2  0.0006166745823446492802411000866413814947009086608886718750000
## 3  0.0002501787346616134882250348514531879118294455111026763916016
## 4  0.0000294798909060135976912316729814378390983620192855596542358
## 5  0.0000218234790719545488843489344787940353853628039360046386719
## 6  0.0000088535680510412586229854886576973171941062901169061660767
## 7  0.0017914012738853503543812184517491914448328316211700439453125
## 8  0.0009382885903262112121600568848123202769784256815910339355469
## 9  0.0001348239681125494701576655875996380018477793782949447631836
## 10 0.0000013569558875775789074329515451755590049742750125005841255
## 11 0.0000007107375915439390617206211891998535179482132662087678909
## 12 0.0000001021268545377872649108357970722249508099821468931622803
## 13 0.0057840616966580975927270102943111851345747709274291992187500
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0000013643475657859583439243233299320579021696175914257764816
## 16 0.0000000000004857106754824595982789570016222239747178193725041
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000000001145696938456985277283312171491699972437340957
## 19 0.0224999999999999991673327315311325946822762489318847656250000
## 20 0.0000066776797753472399274865707596848807270362158305943012238
## 21 0.0000000000000001745640467031612522788968514235007086808448520
## 22 0.0000000000000000000000000000000000000000143583827581367797582
## 23 0.0000000000000000000000000000000000000000000042613636511423543
## 24 0.0000000000000000000000000000000000000000000000000000001113981
## 25 0.0003308220230715012912144079582077438317355699837207794189453
##                                                       20
## 1  0.000616674582344649280241100086641381494700908660889
## 2  0.000833024805627545386448040698468275877530686557293
## 3  0.000616674582344649280241100086641381494700908660889
## 4  0.000021823479071954548884348934478794035385362803936
## 5  0.000029479890906013597691231672981437839098362019286
## 6  0.000021823479071954548884348934478794035385362803936
## 7  0.000938288590326211212160056884812320276978425681591
## 8  0.001791401273885350354381218451749191444832831621170
## 9  0.000938288590326211212160056884812320276978425681591
## 10 0.000000710737591543939061720621189199853517948213266
## 11 0.000001356955887577578907432951545175559004974275013
## 12 0.000000710737591543939061720621189199853517948213266
## 13 0.000716813114985133783066406643058599001960828900337
## 14 0.005784061696658097592727010294311185134574770927429
## 15 0.000716813114985133783066406643058599001960828900337
## 16 0.000000000000060193649468724564487920130182986752271
## 17 0.000000000000485710675482459598278957001622223974718
## 18 0.000000000000060193649468724564487920130182986752271
## 19 0.000006677679775347239927486570759684880727036215831
## 20 0.022499999999999999167332731531132594682276248931885
## 21 0.000006677679775347239927486570759684880727036215831
## 22 0.000000000000000000000000000000000000000000004261364
## 23 0.000000000000000000000000000000000000000014358382758
## 24 0.000000000000000000000000000000000000000000004261364
## 25 0.000788476060127118755921360460092728317249566316605
##                                                                 21
## 1  0.0002501787346616134882250348514531879118294455111026763916016
## 2  0.0006166745823446492802411000866413814947009086608886718750000
## 3  0.0008330248056275453864480406984682758775306865572929382324219
## 4  0.0000088535680510412586229854886576973171941062901169061660767
## 5  0.0000218234790719545488843489344787940353853628039360046386719
## 6  0.0000294798909060135976912316729814378390983620192855596542358
## 7  0.0001348239681125494701576655875996380018477793782949447631836
## 8  0.0009382885903262112121600568848123202769784256815910339355469
## 9  0.0017914012738853503543812184517491914448328316211700439453125
## 10 0.0000001021268545377872649108357970722249508099821468931622803
## 11 0.0000007107375915439390617206211891998535179482132662087678909
## 12 0.0000013569558875775789074329515451755590049742750125005841255
## 13 0.0000013643475657859583439243233299320579021696175914257764816
## 14 0.0007168131149851337830664066430585990019608289003372192382812
## 15 0.0057840616966580975927270102943111851345747709274291992187500
## 16 0.0000000000000001145696938456985277283312171491699972437340957
## 17 0.0000000000000601936494687245644879201301829867522713872138307
## 18 0.0000000000004857106754824595982789570016222239747178193725041
## 19 0.0000000000000001745640467031612522788968514235007086808448520
## 20 0.0000066776797753472399274865707596848807270362158305943012238
## 21 0.0224999999999999991673327315311325946822762489318847656250000
## 22 0.0000000000000000000000000000000000000000000000000000001113981
## 23 0.0000000000000000000000000000000000000000000042613636511423543
## 24 0.0000000000000000000000000000000000000000143583827581367797582
## 25 0.0003308220230715012912144079582077438317355699837207794189453
##                                                                 22
## 1  0.0000294798909060135976912316729814378390983620192855596542358
## 2  0.0000218234790719545488843489344787940353853628039360046386719
## 3  0.0000088535680510412586229854886576973171941062901169061660767
## 4  0.0008330248056275453864480406984682758775306865572929382324219
## 5  0.0006166745823446492802411000866413814947009086608886718750000
## 6  0.0002501787346616134882250348514531879118294455111026763916016
## 7  0.0000013569558875775789074329515451755590049742750125005841255
## 8  0.0000007107375915439390617206211891998535179482132662087678909
## 9  0.0000001021268545377872649108357970722249508099821468931622803
## 10 0.0017914012738853503543812184517491914448328316211700439453125
## 11 0.0009382885903262112121600568848123202769784256815910339355469
## 12 0.0001348239681125494701576655875996380018477793782949447631836
## 13 0.0000000000004857106754824595982789570016222239747178193725041
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000000001145696938456985277283312171491699972437340957
## 16 0.0057840616966580975927270102943111851345747709274291992187500
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0000013643475657859583439243233299320579021696175914257764816
## 19 0.0000000000000000000000000000000000000000143583827581367797582
## 20 0.0000000000000000000000000000000000000000000042613636511423543
## 21 0.0000000000000000000000000000000000000000000000000000001113981
## 22 0.0224999999999999991673327315311325946822762489318847656250000
## 23 0.0000066776797753472399274865707596848807270362158305943012238
## 24 0.0000000000000001745640467031612522788968514235007086808448520
## 25 0.0000150820313937664238202168015545723278592049609869718551636
##                                                       23
## 1  0.000021823479071954548884348934478794035385362803936
## 2  0.000029479890906013597691231672981437839098362019286
## 3  0.000021823479071954548884348934478794035385362803936
## 4  0.000616674582344649280241100086641381494700908660889
## 5  0.000833024805627545386448040698468275877530686557293
## 6  0.000616674582344649280241100086641381494700908660889
## 7  0.000000710737591543939061720621189199853517948213266
## 8  0.000001356955887577578907432951545175559004974275013
## 9  0.000000710737591543939061720621189199853517948213266
## 10 0.000938288590326211212160056884812320276978425681591
## 11 0.001791401273885350354381218451749191444832831621170
## 12 0.000938288590326211212160056884812320276978425681591
## 13 0.000000000000060193649468724564487920130182986752271
## 14 0.000000000000485710675482459598278957001622223974718
## 15 0.000000000000060193649468724564487920130182986752271
## 16 0.000716813114985133783066406643058599001960828900337
## 17 0.005784061696658097592727010294311185134574770927429
## 18 0.000716813114985133783066406643058599001960828900337
## 19 0.000000000000000000000000000000000000000000004261364
## 20 0.000000000000000000000000000000000000000014358382758
## 21 0.000000000000000000000000000000000000000000004261364
## 22 0.000006677679775347239927486570759684880727036215831
## 23 0.022499999999999999167332731531132594682276248931885
## 24 0.000006677679775347239927486570759684880727036215831
## 25 0.000035946278853086757667113088077215365956362802535
##                                                                 24
## 1  0.0000088535680510412586229854886576973171941062901169061660767
## 2  0.0000218234790719545488843489344787940353853628039360046386719
## 3  0.0000294798909060135976912316729814378390983620192855596542358
## 4  0.0002501787346616134882250348514531879118294455111026763916016
## 5  0.0006166745823446492802411000866413814947009086608886718750000
## 6  0.0008330248056275453864480406984682758775306865572929382324219
## 7  0.0000001021268545377872649108357970722249508099821468931622803
## 8  0.0000007107375915439390617206211891998535179482132662087678909
## 9  0.0000013569558875775789074329515451755590049742750125005841255
## 10 0.0001348239681125494701576655875996380018477793782949447631836
## 11 0.0009382885903262112121600568848123202769784256815910339355469
## 12 0.0017914012738853503543812184517491914448328316211700439453125
## 13 0.0000000000000001145696938456985277283312171491699972437340957
## 14 0.0000000000000601936494687245644879201301829867522713872138307
## 15 0.0000000000004857106754824595982789570016222239747178193725041
## 16 0.0000013643475657859583439243233299320579021696175914257764816
## 17 0.0007168131149851337830664066430585990019608289003372192382812
## 18 0.0057840616966580975927270102943111851345747709274291992187500
## 19 0.0000000000000000000000000000000000000000000000000000001113981
## 20 0.0000000000000000000000000000000000000000000042613636511423543
## 21 0.0000000000000000000000000000000000000000143583827581367797582
## 22 0.0000000000000001745640467031612522788968514235007086808448520
## 23 0.0000066776797753472399274865707596848807270362158305943012238
## 24 0.0224999999999999991673327315311325946822762489318847656250000
## 25 0.0000150820313937664238202168015545723278592049609869718551636
##                             25
## 1  0.0001632912431678741887065
## 2  0.0006493360576447230114380
## 3  0.0001632912431678741887065
## 4  0.0000012061013013676200694
## 5  0.0000047961240845296059014
## 6  0.0000012061013013676200694
## 7  0.0000000071885934411270753
## 8  0.0000045297069081992705173
## 9  0.0000000071885934411270753
## 10 0.0000000000000000008000712
## 11 0.0000000000000005041442242
## 12 0.0000000000000000008000712
## 13 0.0000043025960066369215722
## 14 0.0001240942472335887123650
## 15 0.0000043025960066369215722
## 16 0.0000000000277041296343147
## 17 0.0000000007990346076947324
## 18 0.0000000000277041296343147
## 19 0.0003308220230715012912144
## 20 0.0007884760601271187559214
## 21 0.0003308220230715012912144
## 22 0.0000150820313937664238202
## 23 0.0000359462788530867576671
## 24 0.0000150820313937664238202
## 25 0.0224999999999999991673327
lambda=solve(sigma)%*%sigma0[25,-25]
lambda
##              [,1]
## 1   0.00758872879
## 2   0.03051466481
## 3   0.00758872879
## 4  -0.00003276782
## 5   0.00011662647
## 6  -0.00003276782
## 7  -0.00421288727
## 8  -0.01073643525
## 9  -0.00421288727
## 10 -0.00005666790
## 11 -0.00009187561
## 12 -0.00005666790
## 13 -0.00554359594
## 14 -0.00485786885
## 15 -0.00554359594
## 16 -0.00022122643
## 17 -0.00045970408
## 18 -0.00022122643
## 19  0.01587928193
## 20  0.03629635060
## 21  0.01587928193
## 22  0.00070649170
## 23  0.00168519595
## 24  0.00070649170
z_pred0=t(lambda)%*%datos1[,4]
z_pred0
##             [,1]
## [1,] -0.01036865
VarErropred0=sigma[1,1]-t(sigma0[25,-25])%*%solve(sigma)%*%sigma0[25,-25]
VarErropred0
##           [,1]
## [1,] 0.0224392

5.3 Algunas funciones de covarianza espacio temporal no separables

##Funciones de covarianza espacio temporal p vector de parámetros para cada modelo
exp_esp_temp=function(h,u,p){((p[1])^2)*exp(-h/p[2]-u/p[3])}
gauss_esp_temp=function(h,u,p){(p[1]^2)*exp(-(h/p[2])^2-(u/p[3])^2)}
cressie1=function(h,u,p){(p[1]^2/((p[2]^2*u^2+1)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
Gneiting1=function(h,u,p){p[1]^2/((p[2]*u^(2*p[3])+1)^(p[4]))*exp(-(p[6]*h^(2*p[5]))/((p[2]*u^(2*p[3])+1)^(p[4]*p[5])))}
Gneiting2=function(h,u,sigma,p)
{p[1]^2/((2^(p[3]-1))*p[7](p[3])*(p[2]*u^(2*p[3])+1)^(p[4]+p[5]))*
(((p[6]*h)/((p[2]*u^(2*p[3])+1)^(p[5]/2)))^p[3])*
besselK(((p[6]*h)/((p[2]*u^(2*p[3])+1)^(p[5]/2))),p[3])}
Iaco_Cesare=function(h,u,a,b,c){(1+h^p[1]+u^p[2])^(-p[3])}

5.3.1 C R E S S I E - H U A N G (1999)

#sigma:desviacion estandar, a es el parámetros de escala del tiempo, b es el parámetros de escala del espacio, d es la dimensión espacial; a,b positivos
CH_1=function(h,u,p,d){(p[1]^2/((p[2]^2*u^2+1)^(d/2)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
CH_2=function(h,u,p,d){(p[1]^2/((p[2]*abs(u)+1)^(d/2)))*exp(-(p[3]^2*h^2)/(p[2]*abs(u)+1))}
CH_3=function(h,u,p,d){p[1]^2*((p[2]^2)*(u^2)+1)/(((p[2]^2)*(u^2)+1)^2+(p[3]^2)*h^2)^((d+1)/2)}
CH_4=function(h,u,p,d){p[1]^2*(p[2]*abs(u)+1)/((p[2]*abs(u)+1)^2+(p[3]^2)*h^2)^((d+1)/2)}

#el caso mas general de C R E S S I E - H U A N G (1999) es cuando d=2, entonces queda
CH_1=function(h,u,p){(p[1]^2/((p[2]^2*u^2+1)))*exp(-(p[3]^2*h^2)/(p[2]^2*u^2+1))}
CH_2=function(h,u,p){(p[1]^2/((p[2]*abs(u)+1)))*exp(-(p[3]^2*h^2)/(p[2]*abs(u)+1))}
CH_3=function(h,u,p){p[1]^2*((p[2]^2)*(u^2)+1)/(((p[2]^2)*(u^2)+1)^2+(p[3]^2)*h^2)^((3)/2)}
CH_4=function(h,u,p){p[1]^2*(p[2]*abs(u)+1)/((p[2]*abs(u)+1)^2+(p[3]^2)*h^2)^((3)/2)}

5.3.2 Gneiting (2002), combina fun1, fun2 y psi en Gneiting

#fun1
phi1=function(r,c,gama,v){v*exp(-c*r^gama)}                                            #c>0, 0<gama<=1, siempre v=1
phi2=function(r,c,gama,v){((2^(v-1))*gamma(v))^(-1)*(c*r^0.5)^v*besselK(c*r^0.5,v)}    #c>0, v>0
phi3=function(r,c,gama,v){(1+c*r^gama)^(-v)}                                           #c>0, 0<gama<=1, v>0
phi4=function(r,c,gama,v){gama*(2^v)*(exp(c*r^0.5)+exp(-c*r^0.5))^(-v)}                #c>0, v>0, siempre gama=1

#fun2
psi1=function(r,a,alpha,beta){(a*r^alpha+1)^beta}                                      #a>0, 0<alpha<=1, 0<=beta<=1
psi2=function(r,a,alpha,beta){log(a*r^alpha+beta)/log(beta)}                           #a>0, beta>1,  0<alpha<=1
psi3=function(r,a,alpha,beta){(a*r^alpha+beta)/(beta*(a*r^alpha+1))}                   #a>0, 0<beta<=1   0<alpha<=1  

#Cualquier combinación genera una función de covarianza válida
Gneiting=function(h,u,sigma,d,a,alpha,beta,c,gama,v,psi,phi){(sigma^2/(psi((abs(u)^2),a,alpha,beta))^(d/2))*phi(h^2/(psi(abs(u)^2,a,alpha,beta)),c,gama,v)}

#el caso mas general de Gneiting (2002) es cuando d=2, entonces queda
Gneiting=function(h,u,sigma,a,alpha,beta,c,gama,v,psi,phi){(sigma^2/(psi((abs(u)^2),a,alpha,beta)))*phi(h^2/(psi(abs(u)^2,a,alpha,beta)),c,gama,v)}
####IACO_CESSARE
C_IACO_CESSARE=function(h,u,sigma,a,b,alpha,beta,gama){(1 + (h/a)^alpha + (u/b)^beta)^(-gama)}
#(Porcu, 2007) Basado en la función de supervivencia de Dagum 
#función de Dagum
Dagum=function(r,lambda,theta,epsilon){1-1/(1+lambda*r^(-theta))^epsilon}                                                                                     #lamdba, theta in (0,7), epsilon in (0,7)
Dagumm=function(r,lambda,theta,epsilon){ifelse(r==0,1,Dagum(r,lambda,theta,epsilon))}

Porcu_sep=function(h,u,lambda_h,theta_h,epsilon_h,lambda_u,theta_u,epsilon_u){Dagumm(h,lambda_h,theta_h,epsilon_h)*Dagumm(u,lambda_u,theta_u,epsilon_u)}      
Porcu_Nsep=function(h,u,lambda_h,theta_h,epsilon_h,lambda_u,theta_u,epsilon_u,vartheta){vartheta*Dagumm(h,lambda_h,theta_h,epsilon_h)+(1-vartheta)*Dagumm(u,lambda_u,theta_u,epsilon_u)}

6 Pulimiento de medianas

Esta es una alternativa al modelamiento de la media cuando los modelos de regresión polinómicos usuales no logran el objetivo de eliminar la tendencia ya sea porque el tipo de tendencia corresponde mas a unas ventanas móviles o porque hay presentes datos atípicos.

6.1 Cargar librerias

Lista de librerías con link a la documentación.

library(gstat)
library(sp)
library(mvtnorm)

6.2 Grilla de las ubicaciones espaciales.

n_x <- 4
n_y <- 6
x <- seq(0, 1, len = n_x)
y <- seq(0, 1, len = n_y)
coordenadas <- as.data.frame(expand.grid(x, y))
names(coordenadas) <- c("X", "Y")

Encabezado coordenadas

X Y
0.0000000 0.0
0.3333333 0.0
0.6666667 0.0
1.0000000 0.0
0.0000000 0.2
0.3333333 0.2

6.3 Definición de objeto VGM

Esto define un objeto vgm que es el tipo de objeto que usa el paquete gstat para los modelos teóricos de variograma. Con este objeto se pueden definir modelos anidados.

vario <- vgm(10, # Punto de silla
             "Exp", # Modelo, ver documentación
             0.5)  # Rango
print(vario)
##   model psill range
## 1   Exp    10   0.5

6.4 Matriz de varianza dadas coordenadas.

coordinates(coordenadas) <- ~X + Y
class(coordenadas) # Cambio de objedto dataframe a sp
## [1] "SpatialPoints"
## attr(,"package")
## [1] "sp"
cov_mat <- vgmArea(coordenadas, # Matriz de ubiaciones SP
        vgm = vario) # VGM object

print(dim(cov_mat))
## [1] 24 24

6.5 Simulación.

Simulación dada la media y la matriz de varianza

mu  <- rep(0, n_x * n_y) # Media del proceso
simu <- rmvnorm(1,
                mean = mu,
                sigma = cov_mat)
print(simu[1:5])
## [1] -2.5513037  0.9276826 -3.6661586 -0.6549925 -1.1938576

6.6 Pulimiento de medianas

Unir las coordenadas con la columna de simulación

data <- as.data.frame(cbind(coordenadas@coords,
                            Simula = t(simu)))
names(data) <- c("X", "Y", "Var")
print(head(data))
##           X   Y        Var
## 1 0.0000000 0.0 -2.5513037
## 2 0.3333333 0.0  0.9276826
## 3 0.6666667 0.0 -3.6661586
## 4 1.0000000 0.0 -0.6549925
## 5 0.0000000 0.2 -1.1938576
## 6 0.3333333 0.2 -2.7590614

Reshape para matriz, esto transforma la tabla de datos en matriz

tabla <- reshape2::dcast(data,
                         X ~ Y,
                         value.var = "Var")
rownames(tabla) <- tabla[, 1]
tabla <- tabla[, c(-1)]
print(tabla)
##                            0       0.2        0.4        0.6
## 0                 -2.5513037 -1.193858  3.6188035  2.0630539
## 0.333333333333333  0.9276826 -2.759061 -1.0523709  4.8051856
## 0.666666666666667 -3.6661586 -3.658275 -0.8451633  0.2559103
## 1                 -0.6549925 -1.863424 -7.3200303 -4.7032245
##                         0.8          1
## 0                  3.085683  7.8949942
## 0.333333333333333  4.220137  1.5338289
## 0.666666666666667  1.432050 -0.4119245
## 1                 -4.584308 -1.2695238

Pulimiento de medianas de la tabla

med <- medpolish(tabla)
## 1: 42.82888
## 2: 41.35189
## Final: 41.35189
geo_data <- reshape2::melt(med$residuals)
print(med)
## 
## Median Polish Results (Dataset: "tabla")
## 
## Overall: 0.08855764
## 
## Row Effects:
##                 0 0.333333333333333 0.666666666666667 
##         1.1901479         0.9456328        -0.9456328 
##                 1 
##        -4.5026503 
## 
## Column Effects:
##          0        0.2        0.4        0.6        0.8 
## -1.4577956 -2.6368817 -1.0373247  0.9486669  2.0480517 
##          1 
##  1.8221036 
## 
## Residuals:
##                         0      0.2     0.4      0.6      0.8
## 0                 -2.3722  0.16432  3.3774 -0.16432 -0.24107
## 0.333333333333333  1.3513 -1.15637 -1.0492  2.82233  1.13789
## 0.666666666666667 -1.3513 -0.16432  1.0492  0.16432  0.24107
## 1                  5.2169  5.18755 -1.8686 -1.23780 -2.21827
##                         1
## 0                  4.7942
## 0.333333333333333 -1.3225
## 0.666666666666667 -1.3770
## 1                  1.3225

Reshape de los datos, con efecto de la fila y la columna

tabla_residuales <- as.data.frame(med$residuals)
names(tabla_residuales) <- med$col
rownames(tabla_residuales) <- med$row
geo_data <- reshape2::melt(as.matrix(tabla_residuales))

geo_data <- cbind(data,
                  geo_data,
                  med$overall)
names(geo_data) <- c("X",
                     "Y",
                     "Var",
                     "Efecto fila",
                     "Efecto columa",
                     "Residual",
                     "Efecto Global")
print(geo_data)
##            X   Y        Var Efecto fila Efecto columa
## 1  0.0000000 0.0 -2.5513037   1.1901479    -1.4577956
## 2  0.3333333 0.0  0.9276826   0.9456328    -1.4577956
## 3  0.6666667 0.0 -3.6661586  -0.9456328    -1.4577956
## 4  1.0000000 0.0 -0.6549925  -4.5026503    -1.4577956
## 5  0.0000000 0.2 -1.1938576   1.1901479    -2.6368817
## 6  0.3333333 0.2 -2.7590614   0.9456328    -2.6368817
## 7  0.6666667 0.2 -3.6582755  -0.9456328    -2.6368817
## 8  1.0000000 0.2 -1.8634239  -4.5026503    -2.6368817
## 9  0.0000000 0.4  3.6188035   1.1901479    -1.0373247
## 10 0.3333333 0.4 -1.0523709   0.9456328    -1.0373247
## 11 0.6666667 0.4 -0.8451633  -0.9456328    -1.0373247
## 12 1.0000000 0.4 -7.3200303  -4.5026503    -1.0373247
## 13 0.0000000 0.6  2.0630539   1.1901479     0.9486669
## 14 0.3333333 0.6  4.8051856   0.9456328     0.9486669
## 15 0.6666667 0.6  0.2559103  -0.9456328     0.9486669
## 16 1.0000000 0.6 -4.7032245  -4.5026503     0.9486669
## 17 0.0000000 0.8  3.0856834   1.1901479     2.0480517
## 18 0.3333333 0.8  4.2201366   0.9456328     2.0480517
## 19 0.6666667 0.8  1.4320504  -0.9456328     2.0480517
## 20 1.0000000 0.8 -4.5843084  -4.5026503     2.0480517
## 21 0.0000000 1.0  7.8949942   1.1901479     1.8221036
## 22 0.3333333 1.0  1.5338289   0.9456328     1.8221036
## 23 0.6666667 1.0 -0.4119245  -0.9456328     1.8221036
## 24 1.0000000 1.0 -1.2695238  -4.5026503     1.8221036
##      Residual Efecto Global
## 1  -2.3722137    0.08855764
## 2   1.3512877    0.08855764
## 3  -1.3512877    0.08855764
## 4   5.2168958    0.08855764
## 5   0.1643186    0.08855764
## 6  -1.1563701    0.08855764
## 7  -0.1643186    0.08855764
## 8   5.1875505    0.08855764
## 9   3.3774227    0.08855764
## 10 -1.0492366    0.08855764
## 11  1.0492366    0.08855764
## 12 -1.8686129    0.08855764
## 13 -0.1643186    0.08855764
## 14  2.8223282    0.08855764
## 15  0.1643186    0.08855764
## 16 -1.2377987    0.08855764
## 17 -0.2410739    0.08855764
## 18  1.1378945    0.08855764
## 19  0.2410739    0.08855764
## 20 -2.2182674    0.08855764
## 21  4.7941850    0.08855764
## 22 -1.3224652    0.08855764
## 23 -1.3769530    0.08855764
## 24  1.3224652    0.08855764

Validación de la descomposición

valida <- cbind(geo_data$Var,
                geo_data[["Efecto fila"]] +
                geo_data[["Efecto columa"]] +
                geo_data[["Residual"]] +
                geo_data[["Efecto Global"]])
valida <- as.data.frame(valida)
names(valida) <- c("datos", "suma")
print(valida)
##         datos       suma
## 1  -2.5513037 -2.5513037
## 2   0.9276826  0.9276826
## 3  -3.6661586 -3.6661586
## 4  -0.6549925 -0.6549925
## 5  -1.1938576 -1.1938576
## 6  -2.7590614 -2.7590614
## 7  -3.6582755 -3.6582755
## 8  -1.8634239 -1.8634239
## 9   3.6188035  3.6188035
## 10 -1.0523709 -1.0523709
## 11 -0.8451633 -0.8451633
## 12 -7.3200303 -7.3200303
## 13  2.0630539  2.0630539
## 14  4.8051856  4.8051856
## 15  0.2559103  0.2559103
## 16 -4.7032245 -4.7032245
## 17  3.0856834  3.0856834
## 18  4.2201366  4.2201366
## 19  1.4320504  1.4320504
## 20 -4.5843084 -4.5843084
## 21  7.8949942  7.8949942
## 22  1.5338289  1.5338289
## 23 -0.4119245 -0.4119245
## 24 -1.2695238 -1.2695238

7 Introducción proceso espacial bivariado

Martha Bohorquez

19/5/2022

7.1 Librerías

library(geoR)
library(mvtnorm)

7.2 Ubicaciones: En este caso se supone que ambos procesos están observados en los mismos lugares

x=seq(0,1,len=3)
y=seq(0,1,len=4)
coordenadas=expand.grid(x,y)
Mat_dist=as.matrix(dist(coordenadas))

7.3 Modelo lineal de coregionalización

Cova1=function(h,a){exp(-h/a)}
Cova2=function(h,a){ifelse(h <= a, 1-1.5*(h/a)+0.5*(h/a)^3, 0)}
B1=matrix(c(26.3,0.3,0.3,2.1),nrow=2,byrow=T)
B2=matrix(c(2.1,1.3,1.3,17.5),nrow=2,byrow=T)
Mat_Cov_bloque11=B1[1,1]*Cova1(Mat_dist,1)+B2[1,1]*Cova2(Mat_dist,0.5)
Mat_Cov_bloque22=B1[2,2]*Cova1(Mat_dist,1)+B2[2,2]*Cova2(Mat_dist,0.5)
Mat_Cov_bloque12=B1[1,2]*Cova1(Mat_dist,1)+B2[1,2]*Cova2(Mat_dist,0.5)
Mat_Cov_bloque21=B1[2,1]*Cova1(Mat_dist,1)+B2[2,1]*Cova2(Mat_dist,0.5)
MAT_COV=rbind(cbind(Mat_Cov_bloque11,Mat_Cov_bloque12),cbind(Mat_Cov_bloque21,Mat_Cov_bloque22))
dim(MAT_COV)
## [1] 24 24
det(MAT_COV)
## [1] 349416576425414152341717778432

7.4 Simulación de un proceso espacial Gaussiano bivariado

sim1=rmvnorm(1,mean=rep(0,2*nrow(coordenadas)), sigma=MAT_COV)
datos=cbind(coordenadas,z1=sim1[1:12],z2=sim1[13:24])

8 Geoestadística con sgeostat

8.1 Data Load

aquifer=read.table("data/aquifer.txt",head=T,dec=",")
head(aquifer)
##        Este     Norte Profundidad
## 1  42.78275 127.62282        1464
## 2 -27.39691  90.78732        2553
## 3  -1.16289  84.89600        2158
## 4 -18.61823  76.45199        2455
## 5  96.46549  64.58058        1756
## 6 108.56243  82.92325        1702

8.2 Libraries

library(scatterplot3d)
library(ggplot2)
library(cowplot)
library(sgeostat)

8.3 Including Plots

g1=ggplot(aquifer, aes(Profundidad, Este)) + 
  geom_point() + 
  geom_line() +
  xlab("Este") + 
  ylab("Profundidad")

g2=ggplot(aquifer, aes(Profundidad, Norte)) + 
  geom_point() + 
  geom_line() +
  xlab("Norte") + 
  ylab("Profundidad")

g3=ggplot(aquifer, aes(Profundidad, Este*Norte)) + 
  geom_point() + 
  geom_line() +
  xlab("Interacción este,norte") + 
  ylab("Profundidad")
plot_grid(g1,g2,g3)

cor(aquifer)
##                   Este      Norte Profundidad
## Este         1.0000000  0.1147565  -0.7788885
## Norte        0.1147565  1.0000000  -0.6200923
## Profundidad -0.7788885 -0.6200923   1.0000000
scatterplot3d(aquifer, highlight.3d=TRUE, col.axis="blue",
col.grid="lightblue", main="Tendencia de Profundidad", pch=20)

reg1 <- lm(Profundidad ~ Este + Norte, data = aquifer)
residuales1  <-  residuals(reg1)
summary(reg1)
## 
## Call:
## lm(formula = Profundidad ~ Este + Norte, data = aquifer)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -366.96 -161.53  -30.71  148.15  651.20 
## 
## Coefficients:
##              Estimate Std. Error t value            Pr(>|t|)
## (Intercept) 2591.4302    38.9599   66.52 <0.0000000000000002
## Este          -6.7514     0.3438  -19.64 <0.0000000000000002
## Norte         -5.9872     0.4066  -14.73 <0.0000000000000002
##                
## (Intercept) ***
## Este        ***
## Norte       ***
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 203.3 on 82 degrees of freedom
## Multiple R-squared:  0.8921, Adjusted R-squared:  0.8894 
## F-statistic: 338.9 on 2 and 82 DF,  p-value: < 0.00000000000000022
anova(reg1)
## Analysis of Variance Table
## 
## Response: Profundidad
##           Df   Sum Sq  Mean Sq F value                Pr(>F)
## Este       1 19045642 19045642  460.95 < 0.00000000000000022
## Norte      1  8960172  8960172  216.86 < 0.00000000000000022
## Residuals 82  3388069    41318                              
##              
## Este      ***
## Norte     ***
## Residuals    
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
reg2 <- lm(Profundidad ~ Este*Norte, data = aquifer)
residuales2  <-  residuals(reg2)
summary(reg2)
## 
## Call:
## lm(formula = Profundidad ~ Este * Norte, data = aquifer)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -406.30 -138.88  -13.04  129.36  722.48 
## 
## Coefficients:
##                Estimate  Std. Error t value
## (Intercept) 2627.069474   38.325720  68.546
## Este          -8.287218    0.565845 -14.646
## Norte         -6.648559    0.432667 -15.366
## Este:Norte     0.024524    0.007401   3.314
##                         Pr(>|t|)    
## (Intercept) < 0.0000000000000002 ***
## Este        < 0.0000000000000002 ***
## Norte       < 0.0000000000000002 ***
## Este:Norte               0.00138 ** 
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 191.9 on 81 degrees of freedom
## Multiple R-squared:  0.905,  Adjusted R-squared:  0.9014 
## F-statistic: 257.1 on 3 and 81 DF,  p-value: < 0.00000000000000022
anova(reg2)
## Analysis of Variance Table
## 
## Response: Profundidad
##            Df   Sum Sq  Mean Sq F value
## Este        1 19045642 19045642  517.06
## Norte       1  8960172  8960172  243.25
## Este:Norte  1   404448   404448   10.98
## Residuals  81  2983621    36835        
##                           Pr(>F)    
## Este       < 0.00000000000000022 ***
## Norte      < 0.00000000000000022 ***
## Este:Norte              0.001379 ** 
## Residuals                           
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
reg3 <- lm(Profundidad ~ Este*Norte+I(Este^2)*I(Norte^2), data = aquifer)
residuales3  <-  residuals(reg3)
summary(reg3)
## 
## Call:
## lm(formula = Profundidad ~ Este * Norte + I(Este^2) * I(Norte^2), 
##     data = aquifer)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -372.7 -133.6  -20.3  129.9  505.1 
## 
## Coefficients:
##                             Estimate      Std. Error t value
## (Intercept)          2537.5624340948   70.3799189709  36.055
## Este                   -7.7283066535    0.6027554102 -12.822
## Norte                  -3.0747325957    1.7697466886  -1.737
## I(Este^2)              -0.0067922127    0.0059674654  -1.138
## I(Norte^2)             -0.0237215094    0.0090487081  -2.622
## Este:Norte              0.0115491188    0.0096804349   1.193
## I(Este^2):I(Norte^2)    0.0000022515    0.0000009541   2.360
##                                 Pr(>|t|)    
## (Intercept)          <0.0000000000000002 ***
## Este                 <0.0000000000000002 ***
## Norte                             0.0863 .  
## I(Este^2)                         0.2585    
## I(Norte^2)                        0.0105 *  
## Este:Norte                        0.2365    
## I(Este^2):I(Norte^2)              0.0208 *  
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 180.7 on 78 degrees of freedom
## Multiple R-squared:  0.9189, Adjusted R-squared:  0.9126 
## F-statistic: 147.2 on 6 and 78 DF,  p-value: < 0.00000000000000022
anova(reg3)
## Analysis of Variance Table
## 
## Response: Profundidad
##                      Df   Sum Sq  Mean Sq  F value
## Este                  1 19045642 19045642 583.2335
## Norte                 1  8960172  8960172 274.3868
## I(Este^2)             1    55368    55368   1.6955
## I(Norte^2)            1   152170   152170   4.6599
## Este:Norte            1   451567   451567  13.8283
## I(Este^2):I(Norte^2)  1   181854   181854   5.5689
## Residuals            78  2547110    32655         
##                                     Pr(>F)    
## Este                 < 0.00000000000000022 ***
## Norte                < 0.00000000000000022 ***
## I(Este^2)                        0.1967061    
## I(Norte^2)                       0.0339500 *  
## Este:Norte                       0.0003755 ***
## I(Este^2):I(Norte^2)             0.0207829 *  
## Residuals                                     
## ---
## Signif. codes:  
## 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aquifer=data.frame(aquifer,resi=residuales2)
aquifer_points=point(aquifer, x="Este", y="Norte")
aquifer_pair=pair(aquifer_points,num.lags=10)
## ....................................................................................
aquifer_pair$bins
##  [1]  13.55308  40.65923  67.76539  94.87154 121.97770
##  [6] 149.08385 176.19001 203.29616 230.40231 257.50847
aquifer_pair$dist
##    [1]  79.259313  61.292744  79.928307  82.801936  79.529981
##    [6]  84.514408 100.208558 107.152008  89.978304 104.178541
##   [11]  99.251058  88.899718  87.945051  70.165987 101.674210
##   [16] 112.872165 120.961308 119.047906  32.754634  46.156920
##   [21]  27.689647  74.010375  65.729277 107.885946  23.229828
##   [26]  87.355532  98.880862 107.581460 104.100879 104.150438
##   [31]  52.285133  71.583372  76.011219  87.033342  51.194751
##   [36] 129.805262 135.555137 122.851465 125.340545  49.219772
##   [41] 119.707807 119.905108 123.155773 112.001822 114.916408
##   [46] 115.460198 103.829256 104.179897 113.250471  96.543519
##   [51]  97.566287  96.700258  82.781495  63.156546  64.218322
##   [56]  65.835477  24.567616  35.106924  54.832521  45.809186
##   [61]  40.330280  56.110555  43.935695  46.519216  45.713177
##   [66]  50.431563  50.801512  61.124807  55.902846  44.604704
##   [71]  62.449544 185.852432 212.770561 123.323713 143.256052
##   [76] 141.135610 169.641608 148.183229 143.187705 166.176744
##   [81] 149.417056 150.251941 166.077707 163.208576  26.887385
##   [86]  16.809727 126.604452 136.186584 120.744768 128.246553
##   [91] 133.677383 129.683492 130.511843 129.585165 130.769649
##   [96]  94.037999  23.325651 105.307950 123.522448 133.049760
##  [101] 131.853495  97.723076 103.926618  93.928059  79.959358
##  [106]  72.440973 147.319592  99.601194  54.101819  55.632916
##  [111]  65.873035  62.225650  62.421578  91.321524  85.948043
##  [116]  81.564157  68.656804 129.954829  75.968082  81.463104
##  [121]  69.079720  74.315712 101.967004 145.128267 145.470767
##  [126] 148.443085  60.943426  61.309844  61.953184  55.477879
##  [131]  53.875066  81.957351 106.216568 112.476289 109.958325
##  [136]  60.835750  47.647137  41.488835  46.622184  68.602648
##  [141]  50.302378  25.536379 116.404782 113.601262 129.467598
##  [146] 121.021665 123.665659 117.773861 122.244383 123.329873
##  [151]  35.035312  47.569309 123.256491 138.745457 109.244082
##  [156] 133.512160  46.681150  67.213847  63.044705  93.401359
##  [161]  69.021050  65.844134  87.119306  71.711292  71.623479
##  [166]  87.607834  85.955074  19.390467  99.719691 109.743053
##  [171]  93.935947 101.986099 107.639797 102.835886 104.438025
##  [176] 103.169612 103.891523 102.463199  38.358960  81.664216
##  [181]  99.316764 108.881593 107.535211  73.645102  78.352029
##  [186]  70.404750  54.443063  46.299248 120.568893  83.851048
##  [191]  37.288803  44.569863  54.995234  51.090048  51.224206
##  [196]  64.612945  90.728452  88.827991  82.592611 112.322576
##  [201]  72.855185  78.735670  65.600016  69.384909  95.432264
##  [206] 119.389544 119.721763 122.770574  55.218671  57.286526
##  [211]  57.902693  47.558372  47.088151  67.393203  81.542159
##  [216]  87.260250  84.885977  74.954007  55.993465  51.066520
##  [221]  56.378090  58.765641  42.864537  23.977824 103.963732
##  [226]  99.820726 115.962930 105.087557 107.699134 104.691742
##  [231] 109.393102 110.147836   8.935570  20.810342 102.759122
##  [236] 116.226434 124.934060 154.892599  72.895198  93.334966
##  [241]  88.068221 119.167718  90.187266  82.934575 107.549563
##  [246]  89.306141  91.020385 106.441436 102.684866 115.694395
##  [251] 127.345190 108.834938 114.849692 119.917484 117.966887
##  [256] 116.818490 116.460383 119.367633 108.451356  38.352281
##  [261]  89.833391 108.237636 117.699999 116.595192  92.896467
##  [266]  97.006166  89.746654  66.086035  59.478867 135.007450
##  [271] 102.002272  37.463975  38.972587  49.341747  45.626279
##  [276]  45.816907  81.899220  98.972448  95.465680  84.467758
##  [281] 131.106894  61.508958  67.219814  54.379847  59.229277
##  [286] 109.962937 130.949665 131.302206 134.179409  45.391386
##  [291]  46.273339  46.922209  39.289389  37.894974  65.177065
##  [296]  91.335167  97.965398  95.345994  76.615804  61.339143
##  [301]  55.438231  60.800160  74.339658  56.837840  32.970465
##  [306] 121.092218 117.412471 133.534215 123.397383 126.028178
##  [311] 122.060727 126.701758 127.579674  24.388090  36.877600
##  [316] 122.044937 135.607864 105.937898 135.563755  56.560643
##  [321]  76.542772  70.232074 101.732211  70.933202  63.620474
##  [326]  88.187946  69.968883  71.632746  87.060671  83.467540
##  [331]  21.972471  11.475671  26.124366  31.693577   8.380367
##  [336]  30.070646  23.161115   6.209140 170.214009 132.147156
##  [341]  55.124664  51.353913  54.430899  52.534299  51.273236
##  [346]  37.275273  55.886912  54.189985  57.445879  25.084164
##  [351]  93.328281  91.783938 103.143550 104.608208 103.503813
##  [356] 103.379914  36.435484 154.009131 157.641397 164.508297
##  [361]  95.468867 128.230331 132.100422 124.079663 122.594467
##  [366] 129.038237  41.839840  41.896069  44.757880 115.677434
##  [371] 119.651450 119.827187 109.589713 111.574801  96.407188
##  [376]  47.008541  40.863332  42.707944 158.664674 137.180819
##  [381] 135.610055 139.227500 106.066768 108.434174 113.351195
##  [386] 113.851492 106.757833 115.974365 100.119280 101.167428
##  [391] 111.758515 115.045274 114.135715  91.989485  79.260339
##  [396]  76.004414  67.998656 205.317510 244.451025 172.056190
##  [401] 192.215708 185.711843 217.327924 182.775827 170.615069
##  [406] 197.830933 176.903637 181.060655 194.223065 187.354360
##  [411]  33.296292  47.430350  52.185586  28.807239  51.092135
##  [416]  44.174139  25.438238 167.220517 138.182432  76.668261
##  [421]  73.234460  75.787614  73.948195  46.856865  34.717604
##  [426]  51.958332  71.453225  72.567163  37.615554  84.619353
##  [431] 108.114937 120.142473 122.822502 121.306658 121.204583
##  [436]  45.467260 150.802242 155.528833 165.428365  80.320112
##  [441] 146.986778 151.198855 142.329620 141.366327 121.195938
##  [446]  60.430921  60.398169  62.804566 133.290441 137.236403
##  [451] 137.475098 126.631757 128.429927 116.236335  68.515181
##  [456]  62.705490  64.425905 160.345766 139.365571 138.762856
##  [461] 141.704715 103.997489 110.021801 119.507637 102.435955
##  [466]  95.493903 102.297808  87.028525  87.607833  99.959743
##  [471] 102.615712 101.446172 103.006820  90.484265  61.319896
##  [476]  49.232130 222.282477 259.668863 182.625380 203.078010
##  [481] 197.510015 228.831590 196.671699 185.675987 212.538787
##  [486] 192.069019 195.672024 209.541462 203.291640  17.277015
##  [491]  23.884135   9.249078  21.491573  15.286287  11.450345
##  [496] 170.601656 128.115646  43.656904  40.577200  44.579014
##  [501]  42.618833  54.909465  41.310805  59.001264  45.056489
##  [506]  49.596766  26.763715  97.524043  82.632041  93.555096
##  [511]  94.402263  93.505930  93.371758  34.104112 154.626514
##  [516] 157.659004 162.890952 102.794662 117.698059 121.410792
##  [521] 113.788513 112.068493 132.291092  35.751337  35.899705
##  [526]  39.065343 105.718715 109.690766 109.835396  99.942823
##  [531] 102.011910  85.478726  35.550970  29.422107  31.233687
##  [536] 156.692064 135.130369 133.066026 137.003184 106.655003
##  [541] 107.065422 109.472270 119.095243 112.012274 122.341800
##  [546] 106.370848 107.637851 117.219991 120.789057 120.020800
##  [551]  85.776560  73.175783  83.406457  77.404167 195.448896
##  [556] 235.323777 165.387896 185.318152 178.367342 210.034299
##  [561] 174.400625 161.707476 189.023901 167.928111 172.341580
##  [566] 185.133379 177.987519   6.945246  18.627690   4.217605
##  [571]   3.538855  22.028562 184.915166 138.122730  35.972138
##  [576]  26.539157  28.379003  26.522030  71.721980  58.352871
##  [581]  75.597715  48.804976  55.807481  23.615308 114.306908
##  [586]  84.398831  93.853821  92.744883  92.563786  92.399438
##  [591]  48.358436 169.178814 171.715192 175.409523 120.055674
##  [596] 114.439679 117.461202 111.484551 108.914153 148.583251
##  [601]  19.577446  19.802596  23.079974 104.658509 108.556755
##  [606] 108.600018  99.936292 102.205596  81.027208  29.044437
##  [611]  21.176438  23.920446 168.876200 147.370281 144.793973
##  [616] 149.046410 121.438341 120.220201 119.884679 136.150136
##  [621] 129.078555 139.589827 123.613920 124.899192 134.327696
##  [626] 137.950333 137.207183  93.339495  81.293693 100.653031
##  [631]  93.983902 193.807825 235.546757 171.115952 190.506699
##  [636] 182.770249 214.358016 176.713433 162.878229 190.250686
##  [641] 168.884755 173.883827 185.690539 177.870735  23.640710
##  [646]   3.249805   8.715944  26.852987 191.730323 144.155298
##  [651]  37.413293  24.624456  24.175644  22.529215  78.578576
##  [656]  65.132166  82.495350  53.853789  61.349535  23.267715
##  [661] 121.179386  88.369829  97.255209  95.455133  95.537495
##  [666]  95.363629  55.259820 176.026920 178.498974 181.936556
##  [671] 126.455290 116.380751 119.107648 113.815178 110.930536
##  [676] 155.519893  12.710986  12.956907  16.235144 107.498375
##  [681] 111.344344 111.350044 103.186085 105.509780  82.764284
##  [686]  31.481660  23.605644  26.465080 175.342914 153.863801
##  [691] 151.190009 155.500722 128.323224 126.896457 126.040052
##  [696] 142.935659 135.857963 146.206996 130.241022 131.487347
##  [701] 141.084371 144.669825 143.904762  98.908472  87.058888
##  [706] 107.020532  99.686568 196.099877 238.462396 175.954479
##  [711] 195.150446 187.183444 218.698358 180.459255 166.266684
##  [716] 193.596657 172.183164 177.373721 188.809522 180.764665
##  [721]  22.317307  15.382003   3.437885 176.959530 136.512223
##  [726]  50.739946  44.747769  46.981630  45.141200  58.988399
##  [731]  45.024607  63.463361  54.279827  58.812042  18.601119
##  [736] 101.287465  91.823868 102.650552 103.264654 102.464397
##  [741] 102.326113  41.492546 160.841422 164.218445 170.301015
##  [746] 103.849203 126.338500 129.922261 122.587236 120.718604
##  [751] 136.781063  33.464363  33.518140  36.378738 114.682791
##  [756] 118.651173 118.782931 109.017740 111.108731  93.795803
##  [761]  42.831179  35.926540  38.124541 164.265416 142.723612
##  [766] 140.877989 144.677025 112.840201 114.303436 117.796530
##  [771] 122.044237 114.948290 124.313903 108.443027 109.511456
##  [776] 119.985773 123.315227 122.423677  94.769551  82.123940
##  [781]  84.384682  76.119913 204.411257 244.485784 174.506369
##  [786] 194.475190 187.576824 219.241618 183.645520 170.911432
##  [791] 198.236771 177.122156 181.564891 194.307478 187.107556
##  [796]   6.942381  25.654823 188.575925 140.914886  35.323977
##  [801]  23.914020  24.740560  22.954554  75.888428  62.552259
##  [806]  79.731237  50.738832  58.155614  24.520786 118.459733
##  [811]  85.529379  94.584042  93.003840  92.999789  92.828912
##  [816]  52.191595 172.894451 175.328466 178.699841 124.259511
##  [821] 114.206793 117.043094 111.501589 108.727169 152.644482
##  [826]  15.884071  16.143270  19.414825 105.009557 108.874274
##  [831] 108.892461 100.564082 102.871753  80.646317  29.016717
##  [836]  21.088973  23.935007 172.100123 150.623739 147.942845
##  [841] 152.257147 125.225080 123.689040 122.792585 140.344062
##  [846] 133.274448 143.807146 127.831019 129.116781 138.529324
##  [851] 142.159045 141.418952  95.717823  83.841033 104.851824
##  [856]  98.020618 193.818136 235.971588 172.910544 192.153605
##  [861] 184.243655 215.779715 177.703173 163.616639 190.963245
##  [866] 169.562023 174.693966 186.247541 178.275056  18.737051
##  [871] 184.535191 138.925018  39.216710  30.064439  31.620790
##  [876]  29.801376  70.151597  56.595621  74.169502  50.567171
##  [881]  57.179151  20.604436 112.768411  86.670382  96.366737
##  [886]  95.519959  95.245282  95.084623  47.801433 168.708384
##  [891] 171.418563 175.590062 117.739658 117.436853 120.536078
##  [896] 114.368016 111.893482 147.355589  20.552740  20.723073
##  [901]  23.940959 107.376679 111.290272 111.346714 102.504082
##  [906] 104.749293  84.106386  32.092436  24.308347  26.988269
##  [911] 169.147431 147.612011 145.172641 149.343494 120.858841
##  [916] 120.175116 120.569480 134.381034 127.297535 137.532933
##  [921] 121.572330 122.803384 132.500100 136.053707 135.273216
##  [926]  94.604171  82.410214  98.304595  91.143963 196.670144
##  [931] 238.185162 172.840403 192.342218 184.740028 216.357921
##  [936] 179.021894 165.349018 192.729750 171.390538 176.307314
##  [941] 188.262664 180.531009 176.192874 137.037872  53.955044
##  [946]  48.185639  50.355542  48.525718  57.472319  43.474935
##  [951]  62.067580  56.366583  60.478997  19.039807  99.532881
##  [956]  93.984024 104.983203 105.841536 104.956089 104.821782
##  [961]  41.580905 160.015183 163.559936 170.109685 101.285284
##  [966] 129.071761 132.728396 125.214583 123.445490 135.244117
##  [971]  36.207850  36.239004  38.998722 117.169036 121.141050
##  [976] 121.285302 111.378079 113.438740  96.688492  45.996146
##  [981]  39.207933  41.352716 164.178558 142.663354 140.961999
##  [986] 144.666976 112.045807 114.055945 118.276990 119.992693
##  [991] 112.900891 121.970751 106.145670 107.156985 117.879619
##  [996] 121.132970 120.205821  95.955338  83.263654  81.831468
##  [ reached getOption("max.print") -- omitted 2570 entries ]
aquifer_pair$from
##    [1]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
##   [19]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
##   [37]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
##   [55]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
##   [73]  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2
##   [91]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
##  [109]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
##  [127]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
##  [145]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
##  [163]  2  2  2  2  2  3  3  3  3  3  3  3  3  3  3  3  3  3
##  [181]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
##  [199]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
##  [217]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
##  [235]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  4  4  4
##  [253]  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
##  [271]  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
##  [289]  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
##  [307]  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4
##  [325]  4  4  4  4  4  4  5  5  5  5  5  5  5  5  5  5  5  5
##  [343]  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
##  [361]  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
##  [379]  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5
##  [397]  5  5  5  5  5  5  5  5  5  5  5  5  5  5  6  6  6  6
##  [415]  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6
##  [433]  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6
##  [451]  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6
##  [469]  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6
##  [487]  6  6  6  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7
##  [505]  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7
##  [523]  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7
##  [541]  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7
##  [559]  7  7  7  7  7  7  7  7  7  8  8  8  8  8  8  8  8  8
##  [577]  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8
##  [595]  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8
##  [613]  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8
##  [631]  8  8  8  8  8  8  8  8  8  8  8  8  8  8  9  9  9  9
##  [649]  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
##  [667]  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
##  [685]  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
##  [703]  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
##  [721] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
##  [739] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
##  [757] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
##  [775] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
##  [793] 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
##  [811] 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
##  [829] 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
##  [847] 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
##  [865] 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12
##  [883] 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
##  [901] 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
##  [919] 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
##  [937] 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13
##  [955] 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13
##  [973] 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13
##  [991] 13 13 13 13 13 13 13 13 13 13
##  [ reached getOption("max.print") -- omitted 2570 entries ]
aquifer_pair$lags
##    [1] 3  3  3  4  3  4  4  4  4  4  4  4  4  3  4  5  5  5 
##   [19] 2  2  2  3  3  4  1  4  4  4  4  4  2  3  3  4  2  5 
##   [37] 6  5  5  2  5  5  5  5  5  5  4  4  5  4  4  4  4  3 
##   [55] 3  3  1  2  3  2  2  3  2  2  2  2  2  3  3  2  3  7 
##   [73] 8  5  6  6  7  6  6  7  6  6  7  7  1  1  5  6  5  5 
##   [91] 5  5  5  5  5  4  1  4  5  5  5  4  4  4  3  3  6  4 
##  [109] 2  3  3  3  3  4  4  4  3  5  3  4  3  3  4  6  6  6 
##  [127] 3  3  3  3  2  4  4  5  5  3  2  2  2  3  2  1  5  5 
##  [145] 5  5  5  5  5  5  2  2  5  6  5  5  2  3  3  4  3  3 
##  [163] 4  3  3  4  4  1  4  5  4  4  4  4  4  4  4  4  2  4 
##  [181] 4  5  4  3  3  3  3  2  5  4  2  2  3  2  2  3  4  4 
##  [199] 4  5  3  3  3  3  4  5  5  5  3  3  3  2  2  3  4  4 
##  [217] 4  3  3  2  3  3  2  1  4  4  5  4  4  4  5  5  1  1 
##  [235] 4  5  5  6  3  4  4  5  4  4  4  4  4  4  4  5  5  5 
##  [253] 5  5  5  5  5  5  5  2  4  4  5  5  4  4  4  3  3  5 
##  [271] 4  2  2  2  2  2  4  4  4  4  5  3  3  3  3  5  5  5 
##  [289] 5  2  2  2  2  2  3  4  4  4  3  3  3  3  3  3  2  5 
##  [307] 5  5  5  5  5  5  5  1  2  5  6  4  6  3  3  3  4  3 
##  [325] 3  4  3  3  4  4  1  1  1  2  1  2  1  1  7  5  3  2 
##  [343] 3  2  2  2  3  2  3  1  4  4  4  4  4  4  2  6  6  7 
##  [361] 4  5  5  5  5  5  2  2  2  5  5  5  5  5  4  2  2  2 
##  [379] 6  6  6  6  4  5  5  5  4  5  4  4  5  5  5  4  3  3 
##  [397] 3  8  10 7  8  7  9  7  7  8  7  7  8  7  2  2  2  2 
##  [415] 2  2  1  7  6  3  3  3  3  2  2  2  3  3  2  4  4  5 
##  [433] 5  5  5  2  6  6  7  3  6  6  6  6  5  3  3  3  5  6 
##  [451] 6  5  5  5  3  3  3  6  6  6  6  4  5  5  4  4  4  4 
##  [469] 4  4  4  4  4  4  3  2  9  10 7  8  8  9  8  7  8  8 
##  [487] 8  8  8  1  1  1  1  1  1  7  5  2  2  2  2  3  2  3 
##  [505] 2  2  1  4  4  4  4  4  4  2  6  6  7  4  5  5  5  5 
##  [523] 5  2  2  2  4  5  5  4  4  4  2  2  2  6  5  5  6  4 
##  [541] 4  5  5  5  5  4  4  5  5  5  4  3  4  3  8  9  7  7 
##  [559] 7  8  7  6  7  7  7  7  7  1  1  1  1  1  7  6  2  1 
##  [577] 2  1  3  3  3  2  3  1  5  4  4  4  4  4  2  7  7  7 
##  [595] 5  5  5  5  5  6  1  1  1  4  5  5  4  4  3  2  1  1 
##  [613] 7  6  6  6  5  5  5  6  5  6  5  5  5  6  6  4  3  4 
##  [631] 4  8  9  7  8  7  8  7  7  8  7  7  7  7  1  1  1  1 
##  [649] 8  6  2  1  1  1  3  3  4  2  3  1  5  4  4  4  4  4 
##  [667] 3  7  7  7  5  5  5  5  5  6  1  1  1  4  5  5  4  4 
##  [685] 4  2  1  1  7  6  6  6  5  5  5  6  6  6  5  5  6  6 
##  [703] 6  4  4  4  4  8  9  7  8  7  9  7  7  8  7  7  7  7 
##  [721] 1  1  1  7  6  2  2  2  2  3  2  3  3  3  1  4  4  4 
##  [739] 4  4  4  2  6  7  7  4  5  5  5  5  6  2  2  2  5  5 
##  [757] 5  5  5  4  2  2  2  7  6  6  6  5  5  5  5  5  5  5 
##  [775] 5  5  5  5  4  4  4  3  8  10 7  8  7  9  7  7  8  7 
##  [793] 7  8  7  1  1  7  6  2  1  1  1  3  3  3  2  3  1  5 
##  [811] 4  4  4  4  4  2  7  7  7  5  5  5  5  5  6  1  1  1 
##  [829] 4  5  5  4  4  3  2  1  1  7  6  6  6  5  5  5  6  5 
##  [847] 6  5  5  6  6  6  4  4  4  4  8  9  7  8  7  8  7  7 
##  [865] 8  7  7  7  7  1  7  6  2  2  2  2  3  3  3  2  3  1 
##  [883] 5  4  4  4  4  4  2  7  7  7  5  5  5  5  5  6  1  1 
##  [901] 1  4  5  5  4  4  4  2  1  1  7  6  6  6  5  5  5  5 
##  [919] 5  6  5  5  5  6  5  4  4  4  4  8  9  7  8  7  8  7 
##  [937] 7  8  7  7  7  7  7  6  2  2  2  2  3  2  3  3  3  1 
##  [955] 4  4  4  4  4  4  2  6  7  7  4  5  5  5  5  5  2  2 
##  [973] 2  5  5  5  5  5  4  2  2  2  7  6  6  6  5  5  5  5 
##  [991] 5  5  4  4  5  5  5  4  4  4 
##  [ reached getOption("max.print") -- omitted 2570 entries ]
## Levels: 1 2 3 4 5 6 7 8 9 10
aquifer_pair$to
##    [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
##   [19] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
##   [37] 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
##   [55] 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
##   [73] 74 75 76 77 78 79 80 81 82 83 84 85  3  4  5  6  7  8
##   [91]  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
##  [109] 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
##  [127] 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
##  [145] 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
##  [163] 81 82 83 84 85  4  5  6  7  8  9 10 11 12 13 14 15 16
##  [181] 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
##  [199] 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
##  [217] 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
##  [235] 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85  5  6  7
##  [253]  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
##  [271] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
##  [289] 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
##  [307] 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
##  [325] 80 81 82 83 84 85  6  7  8  9 10 11 12 13 14 15 16 17
##  [343] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
##  [361] 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
##  [379] 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
##  [397] 72 73 74 75 76 77 78 79 80 81 82 83 84 85  7  8  9 10
##  [415] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
##  [433] 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
##  [451] 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
##  [469] 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
##  [487] 83 84 85  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
##  [505] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
##  [523] 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
##  [541] 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
##  [559] 77 78 79 80 81 82 83 84 85  9 10 11 12 13 14 15 16 17
##  [577] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
##  [595] 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
##  [613] 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
##  [631] 72 73 74 75 76 77 78 79 80 81 82 83 84 85 10 11 12 13
##  [649] 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
##  [667] 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
##  [685] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
##  [703] 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
##  [721] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
##  [739] 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
##  [757] 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
##  [775] 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
##  [793] 83 84 85 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
##  [811] 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
##  [829] 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
##  [847] 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
##  [865] 81 82 83 84 85 13 14 15 16 17 18 19 20 21 22 23 24 25
##  [883] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
##  [901] 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
##  [919] 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
##  [937] 80 81 82 83 84 85 14 15 16 17 18 19 20 21 22 23 24 25
##  [955] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
##  [973] 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
##  [991] 62 63 64 65 66 67 68 69 70 71
##  [ reached getOption("max.print") -- omitted 2570 entries ]
aquifer.v<-est.variogram(aquifer_points,aquifer_pair,'resi')
g4=ggplot(aquifer, aes(resi, Este)) + 
  geom_point() + 
  geom_line() +
  xlab("Este") + 
  ylab("residuales2")

g5=ggplot(aquifer, aes(resi, Norte)) + 
  geom_point() + 
  geom_line() +
  xlab("Norte") + 
  ylab("residuales2")

plot_grid(g4,g5)

aquifer_points=point(aquifer, x="Este", y="Norte")
fit.trend(aquifer_points,at="Profundidad", np=2, plot.it=TRUE)

## $beta
##        x^0 y^0        x^1 y^0        x^2 y^0        x^0 y^1 
## 2481.430108574   -8.373707821    0.001416675   -2.043419339 
##        x^1 y^1        x^0 y^2 
##    0.026800556   -0.024643707 
## 
## $R
##        x^0 y^0   x^1 y^0    x^2 y^0    x^0 y^1    x^1 y^1
## [1,] -9.219544 -155.6739 -41051.636 -731.67314 -16082.944
## [2,]  0.000000  595.1832   3500.219   57.75539  38829.771
## [3,]  0.000000    0.0000  39397.313 -117.36878   1909.315
## [4,]  0.000000    0.0000      0.000  485.98967  14332.040
## [5,]  0.000000    0.0000      0.000    0.00000  25401.055
## [6,]  0.000000    0.0000      0.000    0.00000      0.000
##        x^0 y^2
## [1,] -85540.31
## [2,]  12491.66
## [3,] -23722.80
## [4,]  91118.22
## [5,]   3240.90
## [6,]  19989.20
## 
## $np
## [1] 2
## 
## $x
##  [1]   42.78275  -27.39691   -1.16289  -18.61823   96.46549
##  [6]  108.56243   88.36356   90.04213   93.17269   97.61099
## [11]   90.62946   92.55262   99.48996  -24.06744  -26.06285
## [16]   56.27842   73.03881   80.26679   80.23009   68.83845
## [21]   76.39921   64.46148   43.39657   39.07769  112.80450
## [26]   54.25899    6.13202   -3.80469   -2.23054   -2.36177
## [31]   -2.18890   63.22428  -10.77860  -18.98889  -38.57884
## [36]   83.14496  -21.80248  -23.56457  -20.11299  -16.62654
## [41]   29.90748  100.91568  101.29544  103.26625  -14.31073
## [46]  -18.13447  -18.12151   -9.88796  -12.16336   11.65754
## [51]   61.69122   69.57896   66.72205  -36.65446  -19.55102
## [56]  -21.29791  -22.36166   21.14719    7.68461   -8.33227
## [61]   56.70724   59.00052   68.96893   70.90225   73.00243
## [66]   59.66237   61.87249   63.70810    5.62706   18.24739
## [71]   85.68824  105.07646 -101.64278 -145.23654  -73.99313
## [76]  -94.48182  -88.84983 -120.25898  -86.02454  -72.79097
## [81] -100.17372  -78.83539  -83.69063  -95.61661  -87.55480
## 
## $y
##  [1] 127.62282  90.78732  84.89600  76.45199  64.58058
##  [6]  82.92325  56.45348  39.25820  33.05852  56.27887
## [11]  35.08169  41.75238  59.15785 184.76636 114.07479
## [16]  26.84826  18.88140  12.61593  14.61795 107.77423
## [21]  95.99380 110.39641  53.61499  61.99805  45.54766
## [26] 147.81987  48.32772  40.40450  29.91113  33.82002
## [31]  33.68207  79.49924 175.11346 171.91695 158.52742
## [36] 159.11559  15.02551   9.41441  22.09269  17.25621
## [41] 175.12875  22.97808  22.96385  20.34239  31.26545
## [46]  30.18118  29.53241  38.14483  39.11081  18.73347
## [51]  32.94906  33.80841  33.93264 150.91457 137.78404
## [56] 131.82542 137.13680 139.26199 126.83751 107.77691
## [61] 171.26443 164.54863 177.24820 161.38136 162.98959
## [66] 170.10544 174.30177 173.91454  79.08730  77.39191
## [71] 139.81702 132.03181  10.65106  28.02333  87.97270
## [76]  86.62606  76.70991  80.76485  54.36334  43.09215
## [81]  42.89881  40.82141  46.50482  35.82183  29.39267
## 
## $z
##  [1] 1464 2553 2158 2455 1756 1702 1805 1797 1714 1466 1729
## [12] 1638 1736 1476 2200 1999 1680 1806 1682 1306 1722 1437
## [23] 1828 2118 1725 1606 2648 2560 2544 2386 2400 1757 1402
## [34] 1364 1735 1376 2729 2766 2736 2432 1024 1611 1548 1591
## [45] 2540 2352 2528 2575 2468 2646 1739 1674 1868 1865 1777
## [56] 1579 1771 1408 1527 2003 1386 1089 1384 1030 1092 1161
## [67] 1415 1231 2300 2238 1038 1332 3510 3490 2594 2650 2533
## [78] 3571 2811 2728 3136 2553 2798 2691 2946
## 
## $residuals
##  [1] -145.932017  296.391955   20.569629  155.586776
##  [5]  136.944207  210.578982  112.643763   81.535500
##  [9]   12.407325 -165.733666   11.643984  -55.843867
## [13]  123.038140  130.250727  132.838620   16.473072
## [17] -186.973641   -9.864104 -133.020821 -298.072286
## [21]   98.737035 -175.328351 -174.667016  118.113364
## [25]  176.632628  200.333264  366.232978  173.604750
## [29]  128.842139  -15.778284   -1.005758  -17.176812
## [33]   -5.743382 -109.803640   35.578021  175.509274
## [37]  109.375693  113.827801  154.658230 -138.758151
## [41] -234.947039  -41.999962 -102.169175  -45.349545
## [45]   38.415648 -182.959426   -9.456222  134.544149
## [49]   14.873572  303.070200 -191.631118 -197.446346
## [53]  -23.989926   92.632496  -47.092725 -308.538280
## [57]  -72.511843 -213.402614 -260.643390  -17.741523
## [61]  187.380986 -159.999448  282.152142 -199.908135
## [65] -116.838018  -37.190026  262.093246   81.109636
## [69]  169.467368  176.796541 -289.932780   42.387375
## [73]  216.381585  -51.786437   30.159248  -53.946573
## [77] -219.188525  648.160187  -92.004756 -152.583829
## [81]   49.711612 -386.649271 -141.519561 -407.429504
## [85] -129.126052
## 
## attr(,"class")
## [1] "trend.surface"
g6=ggplot(aquifer.v, aes(resi, Norte)) + 
  geom_point() + 
  geom_line() +
  xlab("Norte") + 
  ylab("residuales2")

g6=ggplot(aquifer.v, aes(bins, classic)) + 
  geom_point() + 
  geom_line() +
  xlab("Rezago espacial, h") + 
  ylab("Estimador clásico del variograma")

g7=ggplot(aquifer.v, aes(bins, robust)) + 
  geom_point() + 
  geom_line() +
  xlab("Rezago espacial, h") + 
  ylab("Estimador robusto 1 del variograma")

g8=ggplot(aquifer.v, aes(bins, med)) + 
  geom_point() + 
  geom_line() +
  xlab("Rezago espacial, h") + 
  ylab("Estimador robusto 2 del variograma")

plot_grid(g6,g7,g8,nrow=1,ncol=3)

#par(mfrow=c(1,3))
print(aquifer.v)
##    lags      bins   classic    robust       med   n
## 1     1  13.55308  43779.20  44355.34  47948.45 285
## 2     2  40.65923  71039.50  71176.29  73188.30 350
## 3     3  67.76539  80041.91  85367.59  93223.52 492
## 4     4  94.87154  67197.27  68067.40  73056.46 719
## 5     5 121.97770  73572.25  68052.99  66133.91 612
## 6     6 149.08385  57650.90  58608.95  58819.91 521
## 7     7 176.19001  65498.82  62167.57  68112.31 356
## 8     8 203.29616 130414.72 107613.55  77805.71 173
## 9     9 230.40231 161738.13 134102.60 123952.77  43
## 10   10 257.50847  35525.99  45217.14  58333.98  19
plot(aquifer.v$robust)

plot(aquifer.v$med)

#points(aquifer.v$robust,col="red")
#points(aquifer.v$med,"blue")
aquifer.vmodExp<-fit.exponential(aquifer.v,c0=0,ce=40000,ae=20,plot.it=TRUE,iterations=30)
## Initial parameter estimates:  0 40000 20

## Iteration: 1 
## Gradient vector:  -4432.441 977.0988 -8.943538 
## New parameter estimates:  0.000001 40977.1 11.05646 
## 
## rse.dif =  3232643827 (rse = 3232643827 )  ;  parm.dist =  977.1397

## Iteration: 2 
## Gradient vector:  -26700.7 22493.46 -2.800242 
## New parameter estimates:  0.000001 63470.56 8.256219 
## 
## rse.dif =  -17644208 (rse = 3214999619 )  ;  parm.dist =  22493.46

## Iteration: 3 
## Gradient vector:  -11057.27 -15597.73 2.315183 
## New parameter estimates:  0.000001 47872.83 10.5714 
## 
## rse.dif =  -3772568 (rse = 3211227051 )  ;  parm.dist =  15597.73

## Iteration: 4 
## Gradient vector:  -27525.12 16431.58 -1.824505 
## New parameter estimates:  0.000001 64304.41 8.746897 
## 
## rse.dif =  3032851 (rse = 3214259902 )  ;  parm.dist =  16431.58

## Iteration: 5 
## Gradient vector:  -20442.22 -7053.019 1.144197 
## New parameter estimates:  0.000001 57251.39 9.891094 
## 
## rse.dif =  -2468665 (rse = 3211791237 )  ;  parm.dist =  7053.019

## Iteration: 6 
## Gradient vector:  -27557.41 7097.539 -0.7122805 
## New parameter estimates:  0.000001 64348.93 9.178813 
## 
## rse.dif =  1486180 (rse = 3213277417 )  ;  parm.dist =  7097.539

## Iteration: 7 
## Gradient vector:  -24787.06 -2758.919 0.3605893 
## New parameter estimates:  0.000001 61590.01 9.539403 
## 
## rse.dif =  -951749.7 (rse = 3212325667 )  ;  parm.dist =  2758.919

## Iteration: 8 
## Gradient vector:  -26691.4 1898.737 -0.1885371 
## New parameter estimates:  0.000001 63488.75 9.350866 
## 
## rse.dif =  471370.4 (rse = 3212797038 )  ;  parm.dist =  1898.737

## Iteration: 9 
## Gradient vector:  -25850.35 -838.0686 0.09276125 
## New parameter estimates:  0.000001 62650.68 9.443627 
## 
## rse.dif =  -249219.6 (rse = 3212547818 )  ;  parm.dist =  838.0686

## Iteration: 10 
## Gradient vector:  -26302.53 450.7265 -0.04631475 
## New parameter estimates:  0.000001 63101.41 9.397312 
## 
## rse.dif =  121873.4 (rse = 3212669692 )  ;  parm.dist =  450.7265

## Iteration: 11 
## Gradient vector:  -26086.54 -215.2624 0.02285916 
## New parameter estimates:  0.000001 62886.14 9.420171 
## 
## rse.dif =  -61031.79 (rse = 3212608660 )  ;  parm.dist =  215.2624

## Iteration: 12 
## Gradient vector:  -26195.52 108.6221 -0.01133309 
## New parameter estimates:  0.000001 62994.77 9.408838 
## 
## rse.dif =  30077.83 (rse = 3212638738 )  ;  parm.dist =  108.6221

## Iteration: 13 
## Gradient vector:  -26142.08 -53.26613 0.005604603 
## New parameter estimates:  0.000001 62941.5 9.414443 
## 
## rse.dif =  -14922.96 (rse = 3212623815 )  ;  parm.dist =  53.26613

## Iteration: 14 
## Gradient vector:  -26168.65 26.48517 -0.002774911 
## New parameter estimates:  0.000001 62967.99 9.411668 
## 
## rse.dif =  7377.216 (rse = 3212631192 )  ;  parm.dist =  26.48517

## Iteration: 15 
## Gradient vector:  -26155.53 -13.07801 0.001373075 
## New parameter estimates:  0.000001 62954.91 9.413041 
## 
## rse.dif =  -3653.216 (rse = 3212627539 )  ;  parm.dist =  13.07801

## Iteration: 16 
## Gradient vector:  -26162.03 6.479831 -0.0006796194 
## New parameter estimates:  0.000001 62961.39 9.412361 
## 
## rse.dif =  1807.514 (rse = 3212629346 )  ;  parm.dist =  6.479831

## Iteration: 17 
## Gradient vector:  -26158.82 -3.20516 0.0003363367 
## New parameter estimates:  0.000001 62958.18 9.412698 
## 
## rse.dif =  -894.6895 (rse = 3212628451 )  ;  parm.dist =  3.20516

## Iteration: 18 
## Gradient vector:  -26160.41 1.586717 -0.0001664615 
## New parameter estimates:  0.000001 62959.77 9.412531 
## 
## rse.dif =  442.763 (rse = 3212628894 )  ;  parm.dist =  1.586717

## Iteration: 19 
## Gradient vector:  -26159.62 -0.7851797 0.00008238305 
## New parameter estimates:  0.000001 62958.98 9.412613 
## 
## rse.dif =  -219.1369 (rse = 3212628675 )  ;  parm.dist =  0.7851797

## Iteration: 20 
## Gradient vector:  -26160.01 0.3886224 -0.00004077272 
## New parameter estimates:  0.000001 62959.37 9.412573 
## 
## rse.dif =  108.4519 (rse = 3212628784 )  ;  parm.dist =  0.3886224

## Iteration: 21 
## Gradient vector:  -26159.82 -0.192328 0.00002017891 
## New parameter estimates:  0.000001 62959.18 9.412593 
## 
## rse.dif =  -53.67477 (rse = 3212628730 )  ;  parm.dist =  0.192328

## Iteration: 22 
## Gradient vector:  -26159.91 0.09518727 -0.000009986825 
## New parameter estimates:  0.000001 62959.28 9.412583 
## 
## rse.dif =  26.56425 (rse = 3212628756 )  ;  parm.dist =  0.09518727

## Iteration: 23 
## Gradient vector:  -26159.86 -0.04710907 0.000004942611 
## New parameter estimates:  0.000001 62959.23 9.412588 
## 
## rse.dif =  -13.14703 (rse = 3212628743 )  ;  parm.dist =  0.04710907

## Iteration: 24 
## Gradient vector:  -26159.89 0.02331501 -0.000002446166 
## New parameter estimates:  0.000001 62959.25 9.412585 
## 
## rse.dif =  6.506637 (rse = 3212628750 )  ;  parm.dist =  0.02331501

## Iteration: 25 
## Gradient vector:  -26159.88 -0.01153889 0.00000121064 
## New parameter estimates:  0.000001 62959.24 9.412587 
## 
## rse.dif =  -3.220223 (rse = 3212628747 )  ;  parm.dist =  0.01153889

## Iteration: 26 
## Gradient vector:  -26159.88 0.005710766 -0.0000005991629 
## New parameter estimates:  0.000001 62959.25 9.412586 
## 
## rse.dif =  1.593733 (rse = 3212628748 )  ;  parm.dist =  0.005710766

## Iteration: 27 
## Gradient vector:  -26159.88 -0.002826337 0.0000002965342 
## New parameter estimates:  0.000001 62959.24 9.412586 
## 
## rse.dif =  -0.7887607 (rse = 3212628747 )  ;  parm.dist =  0.002826337

## Iteration: 28 
## Gradient vector:  -26159.88 0.001398792 -0.0000001467587 
## New parameter estimates:  0.000001 62959.24 9.412586 
## 
## rse.dif =  0.390368 (rse = 3212628748 )  ;  parm.dist =  0.001398792

## Iteration: 29 
## Gradient vector:  -26159.88 -0.0006922786 0.00000007263263 
## New parameter estimates:  0.000001 62959.24 9.412586 
## 
## rse.dif =  -0.1931987 (rse = 3212628748 )  ;  parm.dist =  0.0006922786

## Iteration: 30 
## Gradient vector:  -26159.88 0.0003426161 -0.00000003594667 
## New parameter estimates:  0.000001 62959.24 9.412586 
## 
## rse.dif =  0.09561539 (rse = 3212628748 )  ;  parm.dist =  0.0003426161

## Convergence not achieved!
aquifer.vmodGau<-fit.gaussian(aquifer.v,c0=0,cg=50000,ag=50,plot.it=TRUE,iterations=30)
## Initial parameter estimates:  0 50000 50

## Iteration: 1 
## Gradient vector:  19162.34 -33401.14 -11.41191 
## New parameter estimates:  19162.34 16598.86 38.58809 
## 
## rse.dif =  3299750048 (rse = 3299750048 )  ;  parm.dist =  38507.55

## Iteration: 2 
## Gradient vector:  -1294.927 2010.017 -18.77473 
## New parameter estimates:  17867.41 18608.87 19.81336 
## 
## rse.dif =  -66430135 (rse = 3233319913 )  ;  parm.dist =  2391.1

## Iteration: 3 
## Gradient vector:  3201.043 -2835.169 9.216254 
## New parameter estimates:  21068.46 15773.71 29.02961 
## 
## rse.dif =  -24694350 (rse = 3208625564 )  ;  parm.dist =  4276.09

## Iteration: 4 
## Gradient vector:  -4345.272 4292.413 -6.361973 
## New parameter estimates:  16723.18 20066.12 22.66764 
## 
## rse.dif =  4004881 (rse = 3212630445 )  ;  parm.dist =  6107.884

## Iteration: 5 
## Gradient vector:  53.88685 -4.270081 2.074271 
## New parameter estimates:  16777.07 20061.85 24.74191 
## 
## rse.dif =  -3703977 (rse = 3208926468 )  ;  parm.dist =  54.09555

## Iteration: 6 
## Gradient vector:  -391.4471 384.4526 -0.5571294 
## New parameter estimates:  16385.62 20446.3 24.18478 
## 
## rse.dif =  588163 (rse = 3209514631 )  ;  parm.dist =  548.6666

## Iteration: 7 
## Gradient vector:  29.55911 -27.0943 0.07968918 
## New parameter estimates:  16415.18 20419.21 24.26447 
## 
## rse.dif =  -201438.9 (rse = 3209313192 )  ;  parm.dist =  40.09799

## Iteration: 8 
## Gradient vector:  -6.581211 6.259206 -0.01207028 
## New parameter estimates:  16408.6 20425.47 24.2524 
## 
## rse.dif =  26607.8 (rse = 3209339800 )  ;  parm.dist =  9.082408

## Iteration: 9 
## Gradient vector:  0.9423146 -0.8928955 0.001794561 
## New parameter estimates:  16409.54 20424.57 24.25419 
## 
## rse.dif =  -4077.43 (rse = 3209335722 )  ;  parm.dist =  1.298161

## Iteration: 10 
## Gradient vector:  -0.1413215 0.1339887 -0.0002673761 
## New parameter estimates:  16409.4 20424.71 24.25393 
## 
## rse.dif =  605.1536 (rse = 3209336327 )  ;  parm.dist =  0.194743

## Iteration: 11 
## Gradient vector:  0.02102884 -0.01993597 0.00003982407 
## New parameter estimates:  16409.42 20424.69 24.25397 
## 
## rse.dif =  -90.18701 (rse = 3209336237 )  ;  parm.dist =  0.02897682

## Iteration: 12 
## Gradient vector:  -0.003132718 0.00296995 -0.000005931842 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  13.43229 (rse = 3209336251 )  ;  parm.dist =  0.004316777

## Iteration: 13 
## Gradient vector:  0.0004666088 -0.0004423641 0.0000008835486 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  -2.000768 (rse = 3209336249 )  ;  parm.dist =  0.0006429701

## Iteration: 14 
## Gradient vector:  -0.00006950174 0.00006589049 -0.0000001316048 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0.2980156 (rse = 3209336249 )  ;  parm.dist =  0.00009577091

## Iteration: 15 
## Gradient vector:  0.00001035231 -0.000009814415 0.00000001960261 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  -0.04438972 (rse = 3209336249 )  ;  parm.dist =  0.00001426512

## Iteration: 16 
## Gradient vector:  -0.000001541989 0.000001461872 -0.000000002919836 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0.006611824 (rse = 3209336249 )  ;  parm.dist =  0.000002124808

## Iteration: 17 
## Gradient vector:  0.000000229702 -0.0000002177649 0.0000000004349504 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  -0.0009841919 (rse = 3209336249 )  ;  parm.dist =  0.0000003165203

## Iteration: 18 
## Gradient vector:  -0.0000000342286 0.00000003244849 -0.00000000006480716 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0.0001459122 (rse = 3209336249 )  ;  parm.dist =  0.00000004716456

## Iteration: 19 
## Gradient vector:  0.000000005117361 -0.000000004848551 0.000000000009688533 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  -0.00002241135 (rse = 3209336249 )  ;  parm.dist =  0.000000007051061

## Iteration: 20 
## Gradient vector:  -0.0000000007696674 0.0000000007270391 -0.000000000001463951 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0.000004291534 (rse = 3209336249 )  ;  parm.dist =  0.000000001060296

## Iteration: 21 
## Gradient vector:  0.0000000001036345 -0.00000000009511823 0.0000000000002010728 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  -0.000001430511 (rse = 3209336249 )  ;  parm.dist =  0.0000000001390071

## Iteration: 22 
## Gradient vector:  -0.00000000001632815 0.00000000001786392 -0.00000000000003703972 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0.000001430511 (rse = 3209336249 )  ;  parm.dist =  0.00000000002329446

## Iteration: 23 
## Gradient vector:  -0.000000000003827252 0.000000000002836377 0.000000000000003527592 
## New parameter estimates:  16409.42 20424.69 24.25396 
## 
## rse.dif =  0 (rse = 3209336249 )  ;  parm.dist =  0.00000000000514488 
## 
## Convergence achieved by sums of squares.

## Final parameter estimates:  16409.42 20424.69 24.25396
aquifer.vmodWave<-fit.wave(aquifer.v,c0=0,cw=40000,aw=10,plot.it=TRUE,iterations=30,weighted=T)
## Initial parameter estimates:  0 40000 10

## Iteration: 1 
## Gradient vector:  18650.32 -21981.27 -0.7942028 
## New parameter estimates:  18650.32 18018.73 9.205797 
## 
## rse.dif =  3409704989 (rse = 3409704989 )  ;  parm.dist =  28827.26

## Iteration: 2 
## Gradient vector:  812.9227 -1109.399 -1.187299 
## New parameter estimates:  19463.25 16909.33 8.018498 
## 
## rse.dif =  -289093760 (rse = 3120611230 )  ;  parm.dist =  1375.358

## Iteration: 3 
## Gradient vector:  -6990.158 6973.566 0.9858099 
## New parameter estimates:  12473.09 23882.9 9.004308 
## 
## rse.dif =  24044562 (rse = 3144655792 )  ;  parm.dist =  9873.851

## Iteration: 4 
## Gradient vector:  7025.438 -6960.473 -1.260353 
## New parameter estimates:  19498.53 16922.43 7.743955 
## 
## rse.dif =  -56767551 (rse = 3087888241 )  ;  parm.dist =  9889.639

## Iteration: 5 
## Gradient vector:  -9210.154 9213.61 1.066674 
## New parameter estimates:  10288.37 26136.04 8.810629 
## 
## rse.dif =  175986924 (rse = 3263875165 )  ;  parm.dist =  13027.57

## Iteration: 6 
## Gradient vector:  11994.7 -11983.26 -2.255679 
## New parameter estimates:  22283.07 14152.77 6.55495 
## 
## rse.dif =  -196728543 (rse = 3067146622 )  ;  parm.dist =  16954.98

## Iteration: 7 
## Gradient vector:  -14060.45 14195.04 -1.578095 
## New parameter estimates:  8222.625 28347.81 4.976855 
## 
## rse.dif =  147278852 (rse = 3214425474 )  ;  parm.dist =  19979.87

## Iteration: 8 
## Gradient vector:  -15826.64 16212.91 0.3854677 
## New parameter estimates:  0.000001 44560.72 5.362323 
## 
## rse.dif =  -46983778 (rse = 3167441696 )  ;  parm.dist =  18178.84

## Iteration: 9 
## Gradient vector:  13145.08 -21444.98 -0.8756698 
## New parameter estimates:  13145.08 23115.75 4.486653 
## 
## rse.dif =  -757940879 (rse = 2409500817 )  ;  parm.dist =  25153.13

## Iteration: 10 
## Gradient vector:  -9434763 9682459 25.73116 
## New parameter estimates:  0.000001 9705575 30.21781 
## 
## rse.dif =  1636307005 (rse = 4045807822 )  ;  parm.dist =  9682468

## Iteration: 11 
## Gradient vector:  20962.2 -9688482 0.02156687 
## New parameter estimates:  20962.2 17093.21 30.23938 
## 
## rse.dif =  83628062 (rse = 4129435883 )  ;  parm.dist =  9688504

## Iteration: 12 
## Gradient vector:  7173.136 -8587.116 1.22582 
## New parameter estimates:  28135.34 8506.099 31.4652 
## 
## rse.dif =  -628497356 (rse = 3500938527 )  ;  parm.dist =  11188.94

## Iteration: 13 
## Gradient vector:  2974.651 -2890.861 -4.19572 
## New parameter estimates:  31109.99 5615.237 27.26947 
## 
## rse.dif =  -192443200 (rse = 3308495327 )  ;  parm.dist =  4147.969

## Iteration: 14 
## Gradient vector:  -2399.351 1443.698 15.69929 
## New parameter estimates:  28710.64 7058.936 42.96876 
## 
## rse.dif =  147479203 (rse = 3455974530 )  ;  parm.dist =  2800.25

## Iteration: 15 
## Gradient vector:  4786.661 2165.107 -43.14322 
## New parameter estimates:  33497.3 9224.042 0.000001 
## 
## rse.dif =  -686128323 (rse = 2769846206 )  ;  parm.dist =  5253.728

## Iteration: 16 
## Gradient vector:  -7188.309 -0.0000005926894 0 
## New parameter estimates:  26308.99 9224.042 0.000001 
## 
## rse.dif =  686457465 (rse = 3456303671 )  ;  parm.dist =  7188.309

## Iteration: 17 
## Gradient vector:  -0.000005339325 -0.0000005926894 0 
## New parameter estimates:  26308.99 9224.042 0.000001 
## 
## rse.dif =  0.4889326 (rse = 3456303672 )  ;  parm.dist =  0.000005372118

## Iteration: 18 
## Gradient vector:  0.0000005926854 -0.0000005926894 0 
## New parameter estimates:  26308.99 9224.042 0.000001 
## 
## rse.dif =  0.000002384186 (rse = 3456303672 )  ;  parm.dist =  0.0000008381857

## Iteration: 19 
## Gradient vector:  0.0000005926902 -0.0000005926894 0 
## New parameter estimates:  26308.99 9224.042 0.000001 
## 
## rse.dif =  -0.000001907349 (rse = 3456303672 )  ;  parm.dist =  0.0000008381882

## Iteration: 20 
## Gradient vector:  0.0000005926902 -0.0000005926894 0 
## New parameter estimates:  26308.99 9224.042 0.000001 
## 
## rse.dif =  0 (rse = 3456303672 )  ;  parm.dist =  0.0000008381882 
## 
## Convergence achieved by sums of squares.

## Final parameter estimates:  26308.99 9224.042 0.000001
curve(65000*(1-(14/x)*sin(x/14)),0,300,ylim=c(0,200000))
points(aquifer.v$bins,aquifer.v$classic,col=3)
text(aquifer.v$bins,aquifer.v$classic,aquifer.v$n,col=2)

curve(200000*(1-exp(-x/170)),0,300)
points(aquifer.v$bins,aquifer.v$classic,col=2)

curve(65000*(1-(14/x)*sin(x/14)),0,300,ylim=c(0,200000))
points(aquifer.v$bins,aquifer.v$classic,col=3)
text(aquifer.v$bins,aquifer.v$classic,aquifer.v$n,col=2)

aquifer.vmodExp<-fit.exponential(aquifer.v,c0=0,ce=200000,ae=170,plot.it=TRUE,iterations=30,weighted=T)
## Initial parameter estimates:  0 200000 170

## Iteration: 1 
## Gradient vector:  16365.66 -238859.4 -103.7436 
## New parameter estimates:  16365.66 0.000001 66.25643 
## 
## rse.dif =  3826411368 (rse = 3826411368 )  ;  parm.dist =  200668.5

## Iteration: 2 
## Gradient vector:  7737.246 16547.95 166070861252 
## New parameter estimates:  24102.91 16547.95 166070861318 
## 
## rse.dif =  -767474321 (rse = 3058937047 )  ;  parm.dist =  166070861252

## Iteration: 3 
## Gradient vector:  3355.03 12424786768746 0 
## New parameter estimates:  27457.94 12424786785294 166070861318 
## 
## rse.dif =  -120011141 (rse = 2938925906 )  ;  parm.dist =  12424786768746

## Iteration: 4 
## Gradient vector:  423.3165 -663474885968 0 
## New parameter estimates:  27881.25 11761311899326 166070861318 
## 
## rse.dif =  11801483 (rse = 2950727388 )  ;  parm.dist =  663474885968

## Iteration: 5 
## Gradient vector:  3.873181 -6320523090 0 
## New parameter estimates:  27885.12 11754991376237 166070861318 
## 
## rse.dif =  128956.4 (rse = 2950856345 )  ;  parm.dist =  6320523090

## Iteration: 6 
## Gradient vector:  0.02266712 -36921321 0 
## New parameter estimates:  27885.15 11754954454916 166070861318 
## 
## rse.dif =  752.3639 (rse = 2950857097 )  ;  parm.dist =  36921321

## Iteration: 7 
## Gradient vector:  0.0001316946 -214507.3 0 
## New parameter estimates:  27885.15 11754954240408 166070861318 
## 
## rse.dif =  4.371067 (rse = 2950857102 )  ;  parm.dist =  214507.3

## Iteration: 8 
## Gradient vector:  0.0000007651061 -1246.218 0 
## New parameter estimates:  27885.15 11754954239162 166070861318 
## 
## rse.dif =  0.02539396 (rse = 2950857102 )  ;  parm.dist =  1246.217

## Iteration: 9 
## Gradient vector:  0.000000004444639 -7.24441 0 
## New parameter estimates:  27885.15 11754954239155 166070861318 
## 
## rse.dif =  0.0001482964 (rse = 2950857102 )  ;  parm.dist =  7.244141

## Iteration: 10 
## Gradient vector:  0.00000000002418472 -0.03727549 0 
## New parameter estimates:  27885.15 11754954239155 166070861318 
## 
## rse.dif =  0.0000009536743 (rse = 2950857102 )  ;  parm.dist =  0.03710938 
## 
## Convergence achieved by sums of squares.

## Final parameter estimates:  27885.15 11754954239155 166070861318
aquifer.vmodwave<-fit.wave(aquifer.v,c0=4000,cw=30000,aw=15,plot.it=TRUE,iterations=0,weighted=T)

## Convergence not achieved!
aquifer.vmodExp_0<-fit.exponential(aquifer.v,c0=0,ce=200000,ae=170,plot.it=TRUE,iterations=0,weighted=T)

## Convergence not achieved!
aquifer.vmodwave_0<-fit.wave(aquifer.v,c0=4000,cw=30000,aw=15,plot.it=TRUE,iterations=0,weighted=T)

## Convergence not achieved!
aquifer.spherical<-fit.spherical(aquifer.v,c0=0,cs=35000,as=70,plot.it=TRUE,iterations=0,weighted=T)

## Convergence not achieved!
ggplot(aquifer.v, aes(bins, classic)) + 
  geom_point() + 
  geom_line() +
  xlab("Rezago espacial, h") + 
  ylab("Estimador clásico del variograma")+
  xlim(0, 300) +
  geom_function(aes(color = "Exponencial"),
    fun =~4000+150000*(1-exp(-.x/100)) 
    ) +
  geom_function(aes(color = "Seno cardinal"),
    fun =~4000+30000*(1-((15/.x)*sin(.x/15)))             
    ) + xlab("Rezago espacial") + ylab("Modelos teóricos de semivariogramas") 

Kriging_aquifer <- point(data.frame(list(x=10,y=80)))
Kriging_aquifer <- krige(Kriging_aquifer, aquifer_points, 'resi', aquifer.vmodExp_0)
## 
## Using all points.
##   Preparing the kriging system matrix...
##   Inverting the matrix...
##   Predicting.
Kriging_aquifer
## 
## Point object: x 
## 
##    Locations: 1
## 
##    Attributes:
##       x
##       y
##       do
##       zhat
##       sigma2hat
Kriging_aquifer$sigma2hat
## [1] 7010.452
Kriging_aquifer <- point(data.frame(list(x=10,y=80)))
Kriging_aquifer <- krige(Kriging_aquifer, aquifer_points, 'resi', aquifer.vmodwave_0)
## 
## Using all points.
##   Preparing the kriging system matrix...
##   Inverting the matrix...
##   Predicting.
Kriging_aquifer
## 
## Point object: x 
## 
##    Locations: 1
## 
##    Attributes:
##       x
##       y
##       do
##       zhat
##       sigma2hat
Kriging_aquifer$zhat
## [1] 196.2781
Kriging_aquifer$sigma2hat
## [1] 5169.927
grid <- list(x=seq(min(aquifer$Este),max(aquifer$Este),by=20),y=seq(min(aquifer$Norte),max(aquifer$Norte),by=10))
grid$xr <- range(grid$x)
grid$xs <- grid$xr[2] - grid$xr[1]
grid$yr <- range(grid$y)
grid$ys <- grid$yr[2] - grid$yr[1]
grid$max <- max(grid$xs, grid$ys)
grid$xy <- data.frame(cbind(c(matrix(grid$x, length(grid$x), length(grid$y))),
c(matrix(grid$y, length(grid$x), length(grid$y), byrow=TRUE))))
colnames(grid$xy) <- c("x", "y")
grid$point <- point(grid$xy)
grid$krige <- krige(grid$point,aquifer_points,'resi',aquifer.vmodwave_0,maxdist=180,extrap=FALSE)
## 
## Using points within 180 units of prediction points.
##   Predicting..........................................................................................................................................................................................................................................
op <- par(no.readonly = TRUE)
par(pty="s")
plot(grid$xy, type="n", xlim=c(grid$xr[1], grid$xr[1]+grid$max),ylim=c(grid$yr[1], grid$yr[1]+grid$max))
image(grid$x,grid$y,matrix(grid$krige$zhat,length(grid$x),length(grid$y)),add=TRUE)
contour(grid$x,grid$y,matrix(grid$krige$zhat,length(grid$x),length(grid$y)),add=TRUE)

x11()
op <- par(no.readonly = TRUE)
par(pty="s")
plot(grid$xy, type="n", xlim=c(grid$xr[1], grid$xr[1]+grid$max),ylim=c(grid$yr[1], grid$yr[1]+grid$max))
image(grid$x,grid$y,matrix(grid$krige$sigma2hat,length(grid$x),length(grid$y)), add=TRUE)
contour(grid$x,grid$y,matrix(grid$krige$sigma2hat,length(grid$x),length(grid$y)),add=TRUE)

9 Cokriging

9.1 Librerías

library(sp)
library(gstat)
library(sf)
library(rgdal)
library(ggplot2)
library(plotly)
library(Matrix)

9.2 Descripción de los datos

Cokriging para las variables \(NO2\), \(O3\), y \(NOX\). La variable de principal riesgo es ozono (\(O3\)), así que se usan las otras dos como covariables espaciales. Día 2020/01/16 A las 17 horas.

datos <- read.csv("2_COK_G_stat/Air_polution_cdmx_2020_01_16_17h.csv")
datos <- datos[c("Estacion",
               "X",
               "Y",
               "NO2",
               "O3",
               "NOX")]

pander::pander((datos))
Estacion X Y NO2 O3 NOX
AJU 482901 2117907 NA 50 NA
AJM 478188 2130946 5 51 8
ATI 473346 2164689 20 70 20
CAM 482180 2152665 23 83 24
CCA 481502 2136931 6 46 8
CUA 469366 2141275 9 56 10
CUT 479189 2180751 13 75 14
FAC 474444 2154232 31 71 35
HGM 484020 2146380 25 81 31
IZT 487647 2143367 21 61 23
LLA 495842 2164872 14 81 15
LPR 487650 2160000 NA 64 NA
MER 487445 2147815 23 79 26
MGH 478716 2145543 NA 66 NA
MON 510196 2151776 9 80 10
MPA 498809 2123036 1 50 NA
NEZ 497038 2144394 8 62 9
PED 478557 2136817 6 56 6
SAG 496819 2159801 16 80 16
SFE 472393 2140390 9 66 10
TAH 498890 2128098 3 47 3
TLA 478535 2159383 26 64 30
TLI 481421 2167509 18 86 20
UAX 489113 2134517 NA 54 NA
UIZ 492241 2140751 7 45 7
VIF 489875 2173664 19 80 22
XAL 491355 2159031 27 80 27

9.3 Matrices de coregionalización.

9.3.1 Matriz definida positiva para el modelo Esférico.

mat1 <- cbind(c(30, 30, 30),
              c(30, 50, 30),
              c(30, 30, 35))
#matriz definida positiva "cercana"
mat1 <- data.frame(as.matrix(nearPD(mat1)$mat))
names(mat1) <- c("NO2", "O3", "NOX")
row.names(mat1) <- c("NO2", "O3", "NOX")
pander::pander(mat1)
  NO2 O3 NOX
NO2 30 30 30
O3 30 50 30
NOX 30 30 35

9.3.2 Matriz definida positiva para el modelo efecto Hueco.

mat2 <- cbind(c(13.02, 24.5, 18.739),
              c(24.58, 46.4, 35.36),
              c(18.73, 35.36, 26.95))
mat2 <- data.frame(as.matrix(nearPD(mat2)$mat))
names(mat2) <- c("NO2", "O3", "NOX")
row.names(mat2) <- c("NO2", "O3", "NOX")
pander::pander(mat2)
  NO2 O3 NOX
NO2 13.02 24.54 18.73
O3 24.54 46.4 35.36
NOX 18.73 35.36 26.96

9.4 Definición de objeto en gstat

9.4.1 Semivariogramas univariados

vgmno2 <- vgm(psill = mat1[1, 1],
            model = "Sph",
            range = 6096,
            add.to = vgm(psill = mat2[1, 1],
                         model = "Hol",
                         range = 2294))

vgmo3 <- vgm(psill = mat1[2, 2],
            model = "Sph",
            range = 6096,
            add.to = vgm(psill = mat2[2, 2],
                         model = "Hol",
                         range = 2294))

vgmnox <- vgm(psill = mat1[3, 3],
            model = "Sph",
            range = 6096,
            add.to = vgm(psill = mat2[3, 3],
                         model = "Hol",
                         range = 2294))

9.4.2 Semivarogramas cruzados (Bivariados)

vgmno2_o3 <- vgm(psill = mat1[1, 2], model = "Sph",
            range = 6096,
            add.to = vgm(psill = mat2[1, 2],
                         model = "Hol",
                         range = 2294))

vgmno2_nox <- vgm(psill = mat1[1, 3],
            model = "Sph",
            range = 6096,
            add.to = vgm(psill = mat2[1, 3],
                         model = "Hol",
                         range = 2294))

vgmno3_nox <- vgm(psill = mat1[2, 3],
                  model = "Sph",
                  range = 6096,
                  add.to = vgm(psill = mat2[2, 3],
                               model = "Hol",
                               range = 2294))

9.4.3 gstat

remove_na <- function(frame, vari_) {

    # Remove na from sp object

    datos1 <- frame

    bool <- !is.na(datos1@data[vari_])
    datos1@data <- datos1@data[bool, ]
    datos1@coords <- datos1@coords[bool, ]

    return(datos1)

}

coordinates(datos) <- ~ X + Y

g_st <- gstat(NULL,
              id = "NO2",
              formula = NO2 ~ X + Y,
              model = vgmno2,
              data = remove_na(datos, "NO2"))

g_st <- gstat(g_st,
              id = "O3",
              formula = O3 ~ Y,
              model = vgmo3,
              data = remove_na(datos, "O3"))

g_st <- gstat(g_st,
              id = "NOX",
              formula = NOX ~ Y,
              model = vgmnox,
              data = remove_na(datos, "NOX"))
#Cruzados


g_st <- gstat(g_st,
              id = c("NO2", "O3"),
              model = vgmno2_o3)

g_st <- gstat(g_st,
              id = c("NO2", "NOX"),
              model = vgmno2_nox)

g_st <- gstat(g_st,
              id = c("O3", "NOX"),
              model = vgmno3_nox)


pander::pander(do.call(rbind, g_st$model)[, 1:3])
  model psill range
NO2.1 Hol 13.02 2294
NO2.2 Sph 30 6096
O3.1 Hol 46.4 2294
O3.2 Sph 50 6096
NOX.1 Hol 26.96 2294
NOX.2 Sph 35 6096
NO2.O3.1 Hol 24.54 2294
NO2.O3.2 Sph 30 6096
NO2.NOX.1 Hol 18.73 2294
NO2.NOX.2 Sph 30 6096
O3.NOX.1 Hol 35.36 2294
O3.NOX.2 Sph 30 6096

9.4.4 Estimación del semivariograma

plot(variogram(g_st),
     model = g_st$model,
     pl = T,
     xlab = "Distancias",
     ylab = "Semivarianza")

9.4.5 Mapas de predicción de O3 con las covariables espaciales NO2 y NOX

prediction_plot <- function(g_object, variable, map_path) {

    map <- readOGR(map_path)
    new <- sp::spsample(map, n = 100000, type = "regular")
    coordinates(new) ~ x1 + x2
    colnames(new@coords) <- c("X", "Y")

    predic <- predict(g_object, newdata = new)

    prediction <- data.frame(predic)

    pred <- paste(variable, ".pred", sep = "")

    plot <- ggplot(prediction, aes_string("X", "Y", fill = pred)) +
            geom_tile() +
            scale_fill_viridis_c() +
            theme_void()

    return(plot)

}


variance_plot <- function(g_object, variable, map_path) {

    map <- readOGR(map_path)
    new <- sp::spsample(map, n = 10000, type = "regular")
    coordinates(new) ~ x1 + x2
    colnames(new@coords) <- c("X", "Y")

    predic <- predict(g_object, newdata = new)

    prediction <- data.frame(predic)

    var <- paste(variable, ".var", sep = "")

    plot <- ggplot(prediction, aes_string("X", "Y", fill = var)) +
            geom_tile() +
            scale_fill_viridis_c(option = "inferno",
                                 direction = -1) +
            theme_void()

    return(plot)

}

cv_plot <- function(g_object, variable, map_path) {

    map <- readOGR(map_path)
    new <- sp::spsample(map, n = 10000, type = "regular")
    coordinates(new) ~ x1 + x2
    colnames(new@coords) <- c("X", "Y")

    predic <- predict(g_object, newdata = new)

    prediction <- data.frame(predic)
    pred <- paste(variable, ".pred", sep = "")
    var <- paste(variable, ".var", sep = "")
    aux <- abs(sqrt(prediction[var]) / abs(prediction[pred]))
    aux[aux > 1] <- 1
    prediction["cv"] <- aux

    plot <- ggplot(prediction, aes_string("X", "Y", fill = "cv")) +
            geom_tile() +
            scale_fill_viridis_c(option = "magma",
                                 direction = -1) +
            theme_void()

    return(plot)
}


pl1 <- prediction_plot(g_st, "O3",
                       "2_COK_G_stat/SP/mpiosutm.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/2_COK_G_stat/SP/mpiosutm.shp", layer: "mpiosutm"
## with 54 features
## It has 7 fields
## Linear Model of Coregionalization found. Good.
## [using universal cokriging]
pl2 <- variance_plot(g_st, "O3",
                     "2_COK_G_stat/SP/mpiosutm.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/2_COK_G_stat/SP/mpiosutm.shp", layer: "mpiosutm"
## with 54 features
## It has 7 fields
## Linear Model of Coregionalization found. Good.
## [using universal cokriging]
pl3 <- cv_plot(g_st, "O3",
               "2_COK_G_stat/SP/mpiosutm.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/martha/Documentos/Cursos EE UN/2_COK_G_stat/SP/mpiosutm.shp", layer: "mpiosutm"
## with 54 features
## It has 7 fields
## Linear Model of Coregionalization found. Good.
## [using universal cokriging]
ggplotly(pl1)
ggplotly(pl2)
ggplotly(pl3)